Hack Forums
[Shell] Batch/PowerShell function to ping IP and Port - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Batch/PowerShell function to ping IP and Port (/showthread.php?tid=5878165)



Batch/PowerShell function to ping IP and Port - Sir-Teabag - Aug 25, 2018

Hey all,

With help from Beigevenus we got this little script together to tell you whether a server is online or offline through an exact port, which I'm fairly certain you can't do in Batch alone (the port thing)


Hope it helps someone here! 

Code
set ip=IP to check
set port=1234
call :serverstatus

echo Server is %status%
::will return 'server is offline/online'
pause
::do other stuff here
exit

:serverstatus
if exist %temp%\server.txt del %temp%\server.txt
powershell TNC -ComputerName %ip% -Port %port% >%temp%\server.txt

set database=%temp%\server.txt
for /F "delims=" %%a in ('findstr /I /N "true" %database%') do set "datalookup=%%a"
if "%datalookup%"=="" (set status=offline) else (set status=online)
goto :EOF



RE: Batch/PowerShell function to ping IP and Port - HFDone - Aug 26, 2018

you can use telnet ip/host port


RE: Batch/PowerShell function to ping IP and Port - Sir-Teabag - Aug 26, 2018

Forgot to add a pause/exit in this, fixed it up now.


RE: Batch/PowerShell function to ping IP and Port - backpackid - Aug 27, 2018

Nice one Sir-Teabag! 🤝