How To Ping Specific Port?

A ping is a tool and command used to troubleshoot network and system-related problems. The ping command normally uses the ICMP protocol and make checks if the remote system is up or down without a TCP or UDP. The ping port is a term used to check a remote port which can be TCP or UDP if it is open and accessible.

Why Ping A Specific Port?

Pinging a specific port is used by different users and administrators to check remote service. A Linux administrator, Windows administrator, Network administrator, Application developer, Database Administrator generally ping specific port to identify and solve problems. Below we will list some of the most popular reasons why ping a specific port.

  • The application can not connect database service.
  • If the firewall has configured properly to allow or deny specific ports.
  • Check if the remote SNMP service is running properly.
  • Before attacking the remote port if the port is up and responding properly.

Ping Specific Port with telnet Command

The most popular and basic tool to ping a remote port is the telnet command. Telnet is a tool and protocol created to connect remote systems via command line. Telnet work from the command line and provides simple access to the remte telnet server. Telnet command uses the TCP protocol and first try to connect remote port which is very usefull to check remote port.

By default telnet is not installed for both Linux and Windows systems. In Linux systems like Ubuntu, Debian, Mint, Kali you can install the telnet command like below.

$ sudo apt install telnet

For Windows operating system the telnet client is provided via the Windows Features but not enabled by default. So you should turn on the telnet client feature. Take a look the following tutorial about how to install telnet client in Windows operating systems.

Alternatively, you can use 3rd party tools like Putty for telnet command but it is not practical as expected.

Syntax of the telnet command to ping the remote port is like below. The telnet command only uses the TCP protocol which is the most popular transmission protocol. So only TCP ports can be pinged with the telnet command which can not be used for the UDP ports.

telnet IP PORT
telnet DOMAIN PORT
  • IP or DOMAIN is used to specify the remote system.
  • PORT is the remote system port number which is a number from 9 to 65000.

Let’s ping the remote HTTP port with the telnet command by providing the port number as 80. We will ping the google.com TCP port number 80 like below.

$ telnet google.com 80

The output will be like below where the telnet will try to connect remote system port number 80 and when the connection is established e will see the message “Connected to google.com.


Trying 172.217.18.110...
Connected to google.com.
Escape character is '^]'.

get /
HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Content-Length: 1555
Date: Thu, 12 Nov 2020 01:57:34 GMT

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
...
Ping Specified Port with telnet

Alternatively, we can try to ping a remote port with the IP address. We will just change the domain name with the IP address below.

$ telnet 172.217.18.110 80

We have made a ping port example with a succesfull result but what will be output if the ping port do not works. In the following example we will ping port number 89 which is closed and will not reply the ping request.

$ telnet google.com 89
Trying 172.217.18.110...
Trying 2a00:1450:4001:809::200e...
telnet: Unable to connect to remote host: Network is unreachable

The output will be like below where the “Trying 172.217.18.110…” line will be shown for timeout and then the “telnet: Unable to connect to remote host: Network is unreachable” message will be displayed.

Ping Specified Port with telnet

Ping Specific Port with nc (netcat) Command

The nc or with its well known name netcat is a tool used by security professionals for remote connectivity and management. Similar to the telnet command nc command can be used to ping specific port number for a remote system.

The nc command is provided by the Linux distributions like Ubuntu, Debian, Mint, Kali and can be installed like below.

$ sudo apt install netcat

For Windows operating systems the nc command and executable can be downloaded from alternative locations where one of them is https://github.com/diegocr/netcat .

The syntax of the nc command is very similar to the telnet command. But the difference is -v and -z parameters should be specified. The -v parameter is used for verbose output in order to see the log or status information like connected or not connected. The -z parameter is used for scan mode which will check or scan the specified remote port.

nc -vz DOMAIN PORT
nc -vz IP PORT
  • The DOMAIN is the remote system domain name.
  • The IP is the remote system IP address.
  • The PORT is the remote system port number we want to ping.

Lets make a ping to the HTTP port of the google.com with the following nc command.

$ nc -vz goole.com 80
Connection to goole.com 80 port [tcp/http] succeeded!

We can see that the connection is succeeded which means the remote port number 80 responds to ping requests. We can also use the IP address for the remote system.

$ nc -vz 172.217.18.110 80

In the following example we will ping the google.com domain name pot number 89.

$ nc -vz goole.com 89
nc: connect to goole.com port 89 (tcp) failed: Connection refused

As we can see the result we will get the “Connection refused” message which means the remtoe port do not responds ping.

Ping Specific Port with nmap

The nmap is a security tool used to scan remote systems ports and services. The nmap can be also used to ping a specific port. Nmap can be installed for the Linux distributions like Ubuntu, Debian, Mint, Kali like below.

$ sudo apt install nmap

For Windows operating systems use the official nmap site Windows download section like below.

https://nmap.org/download.html

The syntax of the nmap command for the port ping is like below.

nmap -p PORT_RANGE TARGET
  • PORT_RANGE is the remote port number or protocol name. The PORT_RANGE can be also a range of port numbers too.
  • TARGET is a domain name or IP address. Also the target can be an IP range too which includes multiple sequencial IP addresses.

Lets make an example with the nmap to ping remote port. We will provide the port number with the -p parameter which will be 80 and the remote system is google.com.

$ nmap -p 80 google.com

The nmap is the fastest tool to ping a specified remote port. The command will be executed in 2 seconds and detailed output about the remote port will be provided like below. The line “80/tcp open http” simply expresses that the remote port number 80 responds to pings.

Starting Nmap 7.80 ( https://nmap.org ) at 2020-11-11 18:27 PST
Nmap scan report for google.com (172.217.18.110)
Host is up (0.036s latency).
Other addresses for google.com (not scanned): 2a00:1450:4001:809::200e
rDNS record for 172.217.18.110: zrh04s05-in-f110.1e100.net
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.28 seconds
Ping Specified Port with nmap

Alternatively we can specify the IP address of the remote system we want to ping port.

$ nmap -p 80 172.217.18.110

As stated previously the nmap command can ping multiple ports and IP addresses with a single command. Other tools like nc, telnet can not ping multiple ports with a single command. In the following example, we will ping port numbers between 80 and 90.

$ nmap -p 80-90 google.com

The output will be like below where the open ports will be listed with the STATE open.

Starting Nmap 7.80 ( https://nmap.org ) at 2020-11-11 18:32 PST
Nmap scan report for google.com (172.217.18.110)
Host is up (0.039s latency).
Other addresses for google.com (not scanned): 2a00:1450:4001:809::200e
rDNS record for 172.217.18.110: fra16s42-in-f14.1e100.net
PORT STATE SERVICE
80/tcp open http
81/tcp filtered hosts2-ns
82/tcp filtered xfer
83/tcp filtered mit-ml-dev
84/tcp filtered ctf
85/tcp filtered mit-ml-dev
86/tcp filtered mfcobol
87/tcp filtered priv-term-l
88/tcp filtered kerberos-sec
89/tcp filtered su-mit-tg
90/tcp filtered dnsix
Ping Multiple Specified Ports with nmap

Ping Specific Port with Test-Connection In PowerShell

The Windows operating system provides the strong command line interface named PowerShell with its recent versions. PowerShell provides a lot of useful commands like Test-NetConnection . The Test-NetConnection can be used to ping specified remote port easily and provides detailed information. The Test-NetConnection is the preferred tool over the telnet command for Windows systems. The Test-NetConnection command is by default with PowerShell and Windows so there is not need for extra installation process.

The syntax of the Test-NetConnection command is like below.

Test-NetConnection TARGET -p PORT
  • TARGET is an IP address or domain name to port ping.
  • PORT is the remote system port number.

We will use the Test-NetConnection command to test google.com port number 80.

PS> Test-NetConnection google.com -p 80

The output of the ping remote port with the Test-NetConnection command will be like below. We can see that remote system ComputerName, RemoteAddress, RemotePort, InterfaceAlias, SourceAddress, TcpTectSucceeded information is provided.

ComputerName : google.com
RemoteAddress : 172.217.18.110
RemotePort : 80
InterfaceAlias : Ethernet0
SourceAddress : 192.168.142.130
TcpTestSucceeded : True
Ping Port with PowerShell Test-NetConnection

Lets make another test for the port number 89 for the google.com .

PS> Test-NetConnection google.com -p 80

The output is like below which means the ping port is failed. For failed ping port operations extra information like PingRelyDetails (RTT), TcpTestSucceeded is provided.

WARNING: TCP connect to (172.217.18.110 : 89) failed

ComputerName : google.com
RemoteAddress : 172.217.18.110
RemotePort : 89
InterfaceAlias : Ethernet0
SourceAddress : 192.168.142.130
PingSucceeded : True
PingReplyDetails (RTT) : 46 ms
TcpTestSucceeded : False
Ping Port with PowerShell Test-NetConnection

1 thought on “How To Ping Specific Port?”

Leave a Comment