Test a port and capture a batch test response

Asked

Viewed 81 times

2

I wonder if it is possible for me to run a test to know if a port is open, as with the telnet command, but to get a response as with ping that I can trigger another action with errorlevel 1 or 0. Thanks in advance.

  • Have way to do, soh q have to use program not available on the system.

1 answer

0

You can use "powershell", which comes in the operating system.

powershell.exe -executionpolicy bypass -command " & { $Global:ProgressPreference = 'SilentlyContinue' ; $Resposta = Test-NetConnection -ComputerName 'localhost' -Port 135 -WarningAction 'SilentlyContinue' -InformationLevel 'Quiet' ; $Global:ProgressPreference = 'Continue' ; Exit( $Resposta ) } "

In the above example, errorlevel will be 1 if port 135 is open on the localhost host'.

I tested in powershell 5.1 (Windows 10).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.