How to Ping a Specific Port
Ping is one of the most fundamental tools when it comes to network troubleshooting. It allows you to quickly test whether a given service/port is responding or not. Due the lightweight nature of ICMP packets, it allows ping to quickly fetch useful information about a given system without sending a series of packets that would otherwise overwhelm the host (in some cases).
Although pinging an entire host can be useful for checking if a given host is up, it does not offer much information about if a target port is up.
In this post, we will discuss how you can use various tools to send a ping request to check if a target port on a specific host is alive.
Method 1 - Use Telnet
You are probably familiar with telnet
. Also known as Terminal or Network, Telnet is a command-line utility that allows you perform interactive network communication using the TELNET protocol.
An telnet tutorial is coming up soo. Stay tuned for that.
To ping a specific port using telnet, use the command syntax as:
telnet [ip_address] [port_number]
The telnet command is available in both Windows and Unix systems. However, you may need to enable Telnet in Windows.
To learn how do that, check the link below:
https://geekbits.io/how-to-enable-telenet-in-windows
On macOS, use brew
to install Telnet:
brew install telnet
On Debian and Debian-Based distributions, install telnet:
sudo apt-get install telnet
The example below shows how to use telnet to check if Nginx Server is running.
telnet 67.205.166.236 80
If the service is running, telnet will connect and return an output as:
Trying 67.205.166.236...
Connected to 67.205.166.236.
Escape character is '^]'.
To close the connection, press CTRL + C]
Method 2 - Using Nmap
Nmap is another ‘crazy’ networking tool that every sys admin and security researcher should use. We will be putting out nmap tutorials in a near future. Make sure to subscribe to get notified when we do.
Start by installing nmap:
sudo apt-get install nmap
On macOS:
brew install nmap
REHL:
sudo yum install nmap
Once installed, check if a port is up by running the command:
nmap -p <port> [target_address]
Example:
sudo nmap -p 80 67.205.166.236
Nmap will return detailed information including the latency, port number, associated service and its state. An exmaple output is as shown:
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-02 10:49 EAT
Nmap scan report for 67.205.166.236
Host is up (0.28s latency).
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.65 seconds
Method 3 - Using Netcat
Netcat is another tool you can use to check if a port is up. Check the nectat cheat sheet to learn more.
https://www.geekbits.io/netcat-command-cheat-sheet/
To ping a port using netcat, run the command:
nc -vz [target_address] [port_number]
Example:
sudo nc -zv 67.205.166.236 80
Connection to 67.205.166.236 port 80 [tcp/http] succeeded!
We can see that the connection to the target address and port is successful. This indicates the port/service is up.
Method 3 - Using cURL
We obviously cannot forget to mention cURL in this list. The command syntax is as shown:
curl -s [host:port]
Example:
curl -s 67.205.166.236:80 >/dev/null && echo Connected. || echo Failed.
The command should “Connected” if the port/service is up.
Method 4 - Using Windows PowerShell
In Windows, you can use the Test-NetConnection
cmdlet to test if a port is up and running. The command syntax is as shown:
Test-NetConnection [ip_address] -p [port_number]
Example:
Test-NetConnection 67.205.166.236 -p 80
The command should return details about the target host and the connection status.
ComputerName : 67.205.166.236
RemoteAddress : 67.205.166.236
RemotePort : 80
InterfaceAlias : Ethernet
SourceAddress : 192.168.1.101
TcpTestSucceeded : True
Method 5 - Using PsPing Utility
In Windows, you can also use the PsPing utility which is part of Windows SysInternals tools. Download the tool in the resource below:
https://download.sysinternals.com/files/PSTools.zip
You can then use the command synax below to ping a specific port:
psping [address:port]
Example:
psping.exe 67.205.166.236:80
The command should send ping request to the target address and port and return the output as shown:
PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
TCP connect to 67.205.166.236:80:
5 iterations (warmup 1) ping test:
Connecting to 67.205.166.236:80 (warmup): from 192.168.1.101:59835: 239.30ms
Connecting to 67.205.166.236:80: from 192.168.1.101:59837: 239.56ms
Connecting to 67.205.166.236:80: from 192.168.1.101:59838: 239.36ms
Connecting to 67.205.166.236:80: from 192.168.1.101:59839: 237.90ms
Connecting to 67.205.166.236:80: from 192.168.1.101:59842: 237.86ms
TCP connect statistics for 67.205.166.236:80:
Sent = 4, Received = 4, Lost = 0 (0% loss),
Minimum = 237.86ms, Maximum = 239.56ms, Average = 238.67ms
The above port is up.
Conclusion
In this post, we explored various methods and tools you can use to ping a specific port in both Windows and Unix based systems.
Thanks for reading and catch you in the next one!!