Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Just a quick sanity check here.

Can you ping a specific port of a machine, and if so, can you provide an example?

I'm looking for something like ping ip address portNum.

share|improve this question

migrated from Sep 8 '11 at 13:44

This question came from our site for professional and enthusiast programmers.

18 Answers 18

up vote 380 down vote accepted

You can't ping ports, as Ping is using ICMP which doesn't have the concept of ports. Ports belong to the transport layer protocols like TCP and UDP. However, you could use nmap to see whether ports are open or not

nmap -p 80

Edit: As flokra mentioned, nmap is more than just a ping-for-ports-thingy. It's the security auditers and hackers best friend and comes with tons of cool options. Check the doc for all possible flags.

share|improve this answer
You might want to add -PN to skip the host discovery nmap usually does before testing the given port. – flokra Oct 8 '09 at 10:06
To save some people some trouble: nmap /can/ be installed on windows from link (or google nmap windows), BUT it does not work over VPNs. PaPing didn't seem to be able to scan a range of addresses. I have posted Python script below that will work over VPN to scan a range of ports on a range of addresses. – Mark Ribau Sep 8 '11 at 7:19
For others: nmap doesn't exist on Mac OS X, you can install nmap via homebrew brew install nmap or MacPorts. – Highway of Life Mar 27 '12 at 15:58
nping is better suited for this task than nmap. nping is part of the nmap distribution. – CMCDragonkai Jun 16 '14 at 8:39
Mac OSX has 'Network Utility' which has a port scanner tab – Shanimal Jul 27 '15 at 20:53

Open a telnet session to the specific port, for example:

# telnet 80
Connected to
Escape character is '^]'.

To close your session, hit Ctrl+].

share|improve this answer
netcat works also great and is less verbose. – petrus Sep 9 '11 at 20:17
Telnet works well for this iff the port is a TCP port. – Falcon Momot Feb 14 '13 at 22:29
netcat works with UDP too (nc -u) – tsv.dimitrov Apr 21 '13 at 7:35

You can use PaPing:

C:\>paping.exe -p 80 -c 4
paping v1.5.1 - Copyright (c) 2010 Mike Lovell

Connecting to [] on TCP 80:

Connected to time=24.00ms protocol=TCP port=80
Connected to time=25.00ms protocol=TCP port=80
Connected to time=24.00ms protocol=TCP port=80
Connected to time=24.00ms protocol=TCP port=80

Connection statistics:
        Attempted = 4, Connected = 4, Failed = 0 (0.00%)
Approximate connection times:
        Minimum = 24.00ms, Maximum = 25.00ms, Average = 24.25ms
share|improve this answer
Or instead of paping you could use cryping which has been around much longer and supports pinging of some services as well as ports. – Brian Cryer Sep 10 '10 at 9:47
+1 worked great! – Chris Marisic Feb 8 '11 at 16:38
Can this be used to ping any port or just 80? – Luke Puplett Jul 9 '12 at 16:28
@LukePuplett just change the number 80 in the example. Run it by typing paping.exe <hostname/IP> -p <portnumber> -c <number of attempts> – David Costa Jul 9 '12 at 18:39
+1 - this might be the best answer of them all. – Frederik Nielsen Oct 24 '12 at 11:47
$ nc -vz 80
Connection to 80 port [tcp/http] succeeded!
share|improve this answer
Use with time like in time nc -vz 80 and you'll have sort of an RTT, too. – xebeche Feb 21 '14 at 8:58
Sole solution that works on Amazon EC2 instances without any installation. – Masadow Mar 3 at 15:39
This command works on a Raspberry Pi (Linux distro raspian) – John M yesterday

No, you can't, because ping uses the ICMP protocol, which doesn't even have a concept of ports.

share|improve this answer
I'm pretty sure the use of "ping" was metaphorical. – Luke Puplett Jul 9 '12 at 16:26
Hi Luke, small world :-) modded you up. – Hugh Perkins Feb 19 '13 at 6:20

Ping is very specific but if you want to check whether a port is open or not, and are running a Windows box then PortQry is your friend.

I've only used it for testing Domain Controllers for connectivity issues, but it worked a treat for that, so should work for you.

share|improve this answer
PortQry works great and its only 140kb. Thanks! – SCL Feb 5 '10 at 11:14
+1 PortQry works great for testing localhost. – Chris Masterton Jul 29 '11 at 1:20
PortQry was originally released in 1999/2000 by the MS Exchange team but MS recent version appears to have stunted it by removing the ability to query remote ports (health & safety). – Luke Puplett Jul 9 '12 at 16:31

On Linux you can use hping but it uses TCP, rather than ICMP.

hping -S -V -p 80
share|improve this answer

All very useful answers. I found a simpler one.


share|improve this answer

If you're on a windows installation with powershell v4 or newer, you can use the test-netconnection powershell module:

Test-NetConnection <host> -port <port>

Example: Test-NetConnection -port 80

This cmdlet also has the alias tnc. Eg tnc -port 80

share|improve this answer

Here's a quick and dirty .NET console app:

    static void Main(string[] args)
        string addressArgument = null, portArgument = null;

        System.Net.Sockets.TcpClient tcpClient = null;

            addressArgument = args[0];
            portArgument = args[1];

            int portNumber;
            portNumber = Int32.Parse(portArgument);

            tcpClient = new System.Net.Sockets.TcpClient();
            tcpClient.ReceiveTimeout = tcpClient.SendTimeout = 2000;

            IPAddress address;
            if (IPAddress.TryParse(args[0], out address))
                var endPoint = new System.Net.IPEndPoint(address, portNumber);
                tcpClient.Connect(addressArgument, portNumber);

            Console.WriteLine("Port {0} is listening.", portArgument);
        catch (Exception e)
            if (e is SocketException || e is TimeoutException)
                Console.WriteLine("Not listening on port {0}.", portArgument);
                Console.WriteLine("    portquery [host|ip] [port]");
            if (tcpClient != null)
share|improve this answer

I'm quite sure that Nagios check_tcp probe does what you want. They can be found here and although designed to be used in a Nagios context, they're all standalone programs.

$ ./check_tcp -H host -p 22
TCP OK - 0.010 second response time on port 22|time=0.009946s;0.000000;0.000000;0.000000;10.000000
share|improve this answer

This is the only solution that works for VPNs with the client machine being Windows Vista or Windows 7, as other listed answers simply do not function. This answer was previously deleted and should not have been, as this is the only solution for a real-world common case. Since there is no appeal available for the delete, I am reposting it to save others the frustration I had with trying to use the other answers.

The example below finds which IPs on the VPN that have VNC/port 5900 open with the client running on Windows 7.

A short Python (v2.6.6) script to scan a given list of IPs and Ports:

from socket import *

fTimeOutSec = 5.0
sNetworkAddress = '192.168.1'
aiHostAddresses = range(1,255)
aiPorts = [5900]

print "Starting Scan..."
for h in aiHostAddresses:
    for p in aiPorts:
        s = socket(AF_INET, SOCK_STREAM)
        address = ('%s.%d' % (sNetworkAddress, h))
        result = s.connect_ex((address,p))
        if ( 0 == result ):
            print "%s:%d - OPEN" % (address,p)
        elif ( 10035 == result ):
            #do nothing, was a timeout, probably host doesn't exist
            print "%s:%d - closed (%d)" % (address,p,result)

print "Scan Completed."

Results looked like:

Starting Scan... - closed (10061) - closed (10061) - OPEN - closed (10061)
Scan Completed.

The four variables at the top would need to be changed to be appropriate to whatever timeout, network, hosts, and ports that are needed. 5.0 seconds on my VPN seemed to be enough to work properly consistently, less didn't (always) give accurate results. On my local network, 0.5 was more than enough.

share|improve this answer
Works perfectly on Win 7 XP Pro client / Win Server 2008 R2 to diagnose closed port. (I had to use a 30 second timeout threshold but that may be an issue with specific server environment not a problem with this code) – David Zemens Sep 4 '15 at 2:04

Try curl command, like:

$ curl host:port

For example:

$ curl -s localhost:80 >/dev/null && echo Success. || echo Fail.

Above command will return Fail on a non-zero exit status codes. In some particular cases, such as empty or malformed response (see man curl), you may want to handle specific exit codes as successful, so please check this post for more detailed explanation.

share|improve this answer
I like this because curl is present by default on CentOS, so I don't have to install anything. – bdemarest Jan 12 at 17:34
curl worked on a Raspberry Pi (distro Raspian) – John M yesterday


There's no guarantee that the service running on the port understands ping. It also opens up the question of what "flavor" of port you want to ping, TCP or UDP? Since the ping "protocol" uses neither (ping is implemented using ICMP), it doesn't make a lot of sense.

share|improve this answer

There is a lightweigth tool for it, called tcping:

share|improve this answer
hping mush better, e.g. it can many packets with interval, not just one packet. See c4f4t0r's answer. – Putnik May 5 at 15:30

If you are running a *nix operating system try installing and using "zenmap", it is a GUI for nmap and has several useful scan profiles which are a great help to the new user.

share|improve this answer
Zenmap is also available for windows. – Nick Young Jan 12 at 18:16

i'm feeling lucky on google for “ping a specific port”:, so NO, you cannot ping a specific port

you can use nmap though: nmap -p <port> <host>

share|improve this answer

Try port knocking software. Personally I use KnockKnock ( ). It remembers the combination of ports and the IP.

share|improve this answer
Note that this is Windows only, and the original question didn't specify an OS. – Hugh Perkins Feb 19 '13 at 6:23

protected by Michael Hampton Feb 14 '13 at 22:00

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.