3

I'm trying to make a simple script on cmd (bat file) to check if couple of remote servers are up and up running

i wanted to ping a specific ip and port.
when i got %ERRORLEVEL% = 1 i knew there was a problem and when i got %ERRORLEVEL% = 0 the server was ok

after some fooling around with ping command i saw that you can't ping a specific port...

then i tried using telnet on my script and telnet dosent return any value (to what i could find) if there is a successful Session or not

if anyone got any other way to check if couple servers are running for a script i would appreciate the help. Thanks

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
Danbz
  • 31
  • 1
  • 1
  • 2

4 Answers4

4

if you are using windows, why don't you use PowerShell. here is a sample code to ping to a specfic port

TNC -ComputerName SQLServer01 -Port 1433
Panna Das
  • 611
  • 6
  • 11
2

This is a fully working Batch file that gives "True" or "False" as result:

@echo off
setlocal

if "%~2" equ "" echo Usage: %0 ComputerName Port & goto :EOF

for /F "tokens=3" %%a in ('powershell TNC -ComputerName %~1 -Port %~2') do set "result=%%a"
echo %result%

Be aware that this method may take several seconds to give the result...

Aacini
  • 65,180
  • 12
  • 72
  • 108
1

using powershell:

Test-NetConnection ip_address_here -p port_number_here

e.g

Test-NetConnection 10.0.0.53 -p 3006
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
aris
  • 409
  • 6
  • 8
-2

first you should install telnet client then press window+r and type cmd command prompt open after that put a command telnet remoteIP port

vijay joshi
  • 38
  • 1
  • 10