Check Open Remote TCP Port via Windows Batch File
In this article, we will discuss how to check if a remote TCP or UDP port is open using a Windows batch file. This is a useful tool for system administrators and developers who need to monitor the status of network services and troubleshoot connectivity issues.
Introduction
The telnet command is a useful tool for checking the status of remote TCP ports. By sending a request to a specific port, you can determine if it is open and accepting connections. In this article, we will show you how to use the telnet command in a Windows batch file to check the status of remote TCP ports.
Using the telnet Command
The telnet command is a command-line tool that is used to establish a connection to a remote host using the Telnet protocol. To check the status of a remote TCP port using telnet, you can use the following command:
telnet <hostname> <port>For example, to check if port 80 (HTTP) is open on a remote host with the IP address 192.168.1.1, you would use the following command:
telnet 192.168.1.1 80If the port is open, you will see a blank screen. If the port is closed, you will see an error message similar to the following:
Connecting To 192.168.1.1...Could not open connection to the host, on port 80: Connect failedUsing a Windows Batch File
To check the status of a remote TCP port using a Windows batch file, you can use the following code:
rem check open port
timeout /t 10
telnet <hostname> <port>
if <errorlevel> == 0 (
echo Port <port> on host <hostname> is open
) else (
echo Port <port> on host <hostname> is closed
)This code will check the status of a remote TCP port using the telnet command. If the port is open, it will display a message saying that the port is open. If the port is closed, it will display a message saying that the port is closed.
Using a Windows Batch File to Check Multiple Ports
To check the status of multiple remote TCP ports using a Windows batch file, you can use the following code:
rem check open ports
for %%a in (80, 443, 8080) do (
timeout /t 10
telnet <hostname> %%a
if <errorlevel> == 0 (
echo Port %%a on host <hostname> is open
) else (
echo Port %%a on host <hostname> is closed
)This code will check the status of multiple remote TCP ports (80, 443, and 8080) using the telnet command. If a port is open, it will display a message saying that the port is open. If a port is closed, it will display a message saying that the port is closed.
In this article, we have discussed how to use a Windows batch file to check the status of remote TCP ports using the telnet command. This is a useful tool for system administrators and developers who need to monitor the status of network services and troubleshoot connectivity issues. We have also discussed how to use a Windows batch file to check the status of multiple remote TCP ports.
- The telnet command can be used to check the status of remote TCP ports
- A Windows batch file can be used to automate the process of checking remote TCP