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.

link|improve this question
9  
belongs on serverfault. – Peter Oct 8 '09 at 10:13
feedback

migrated from stackoverflow.com Sep 8 '11 at 13:44

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

13 Answers

up vote 68 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 example.com

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.

link|improve this answer
2  
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
1  
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 at 15:58
feedback

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

# telnet google.com 80
Trying 74.125.226.48...
Connected to google.com.
Escape character is '^]'.

To close your session, hit ctrl-].

link|improve this answer
netcat works also great and is less verbose. – petrus Sep 9 '11 at 20:17
feedback

You can use PaPing:

http://code.google.com/p/paping

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

Connecting to www.l.google.com [209.85.225.147] on TCP 80:

Connected to 209.85.225.147: time=24.00ms protocol=TCP port=80
Connected to 209.85.225.147: time=25.00ms protocol=TCP port=80
Connected to 209.85.225.147: time=24.00ms protocol=TCP port=80
Connected to 209.85.225.147: 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
link|improve this answer
1  
+1 worked great! – Chris Marisic Feb 8 '11 at 16:38
feedback

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

link|improve this answer
feedback

No.

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.

link|improve this answer
feedback

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.

link|improve this answer
PortQry works great and its only 140kb. Thanks! – Dawkins Feb 5 '10 at 11:14
+1 PortQry works great for testing localhost. – Chris Masterton Jul 29 '11 at 1:20
feedback

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
link|improve this answer
feedback

i'm feeling lucky on google for “ping a specific port”: http://philwilks.blogspot.com/2008/01/ping-specific-port.html, so NO, you cannot ping a specific port

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

link|improve this answer
feedback

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.

link|improve this answer
feedback

This is the only solution that works for VPNs on 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 allowed 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 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]

setdefaulttimeout(fTimeOutSec)
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
            pass
        else:
            print "%s:%d - closed (%d)" % (address,p,result)

        s.close()
print "Scan Completed."

Results looked like:

Starting Scan...
192.168.1.1:5900 - closed (10061)
192.168.1.7:5900 - closed (10061)
192.168.1.170:5900 - OPEN
192.168.1.170:5900 - 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. ` 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.

link|improve this answer
feedback

Or instead of paping you could use cryping which has been around much longer and supports pinging of some services as well as ports.

link|improve this answer
feedback

try this simple app http://porttest.blogspot.com/

link|improve this answer
feedback

Try port knocking software. Personally I use KnockKnock ( http://sourceforge.net/projects/knockknock/ ). It remembers the combination of ports and the IP.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown