Wednesday, March 16, 2011

How to find listening / open ports on a computer?

So how do I tell if a TCP or UDP network port is open or not?

Microsoft Windows
1. To find open ports on a computer, you can use netstat command line.

Netstat (network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interface statistics. It is available on Unix, Unix-like, and Windows NT-based operating systems.
It is used for finding problems in the network and to determine the amount of traffic on the network as a performance measurement.

a. To display all open ports, open DOS command, type netstat and press Enter.
b. To list all listening ports, use netstat -an | find /i "listening" command.
c. To see what ports your computer actually communicates with, use netstat -an | find /i "established"
d. To find specified open port, use find switch. For example, to find if the port 3389 is open or not, do netstat -an | find /i "3389".

Example: Port 3389 is closed / not listening
1. netstat -an | find "3389" command shows nothing

2.1. You can also test by telneting to localhost or 127.0.0.1 at specific port you want to check.
telnet localhost 3389  or   telnet 127.0.0.1 3389

The following error message will popup if the port is closed / not listening.
"Connecting To 3389...Could not open connection to the host, on port 23: Connect failed"


Example: Port is open / listening
1. netstat -an | find "3389" command shows "LISTENING" message

2.1. You can also test by telneting to localhost or 127.0.0.1 at specific port you want to check.
telnet localhost 135 or telnet 127.0.0.1 135

2.2. Once you press enter, a blank screen as image below shows that the port is listening.

e. You can use PULIST from the Windows Resource Kit to find which process is using a specified port. For example, pulist | find /i "4125" may display

Process PID User
mad.exe 4125 Chicagotech/blin

Or you can use tasklist to find PID.

Reference:
http://en.wikipedia.org/wiki/Netstat
http://nixcraft.com/getting-started-tutorials/622-windows-how-do-i-tell-if-tcp-network-port-open-not.html
http://www.speedguide.net/faq_in_q.php?qid=115
http://www.howtonetworking.com/command/openport1.htm
http://www.techrepublic.com/blog/security/list-open-ports-and-listening-services/443

Thursday, January 27, 2011

Timestamp ping

Standard ping
Ping utility in windows is very useful to troubleshoot network connectivity, however lacking of timestamp feature is very frustrating. But don't worry as we have alternative for that which is Fping and hrPING. Let's take a look at both tools.

No timestamp in normal ping utility

Fping


hrPING


Fping & hrPING
12/11/2008 07:30 PM 292,864 Fping.exe
16/11/2010 12:19 PM 320,184 hrping.exe
2 File(s) 613,048 bytes






Fping
Fping c-kurity.blogspot.com -T
Fping is a free console program, much like the ping program that comes with windows.
Why use fping instead of the standard windows ping? Fping has the same options as the regular ping as well as several unique options.

Time between pings can be adjusted as needed from 1ms to 5s.
Beep on every successful or unsuccessful reply allowing you to test your network status in the background.
Ping multiple hosts with one simple command.
Read a hostlist from a file
Output redirection to a file for parsing.
Ping with random data, or data you provide
Ping using raw sockets, or use the ICMP dll. The choice is up to you.

Download Fping v2.22 (244k zip)
http://www.kwakkelflap.com/files/fping222.zip

MD5 Checksums:
fping.zip EA8422FFCA2C1103B4DA32FDCD8F1609

Reference:
http://www.kwakkelflap.com/fping.html


hrPING v3.10


C:\c-kurity>hrping.exe c-kurity.blogspot.com -T
This is hrPING v3.10 by cFos Software GmbH -- http://www.cfos.de

Source address is 192.168.1.15; using ICMP echo-request
Pinging c-kurity.blogspot.com [209.85.175.132]
with 32 bytes data (60 bytes IP):

2011-01-28 11:59:40.946: Reply from 209.85.175.132: seq=0001 time=32.212ms TTL=55 ID=02d2
2011-01-28 11:59:41.449: Reply from 209.85.175.132: seq=0002 time=34.929ms TTL=55 ID=02d3
2011-01-28 11:59:41.950: Reply from 209.85.175.132: seq=0003 time=36.550ms TTL=55 ID=02d4
2011-01-28 11:59:42.450: Reply from 209.85.175.132: seq=0004 time=36.018ms TTL=55 ID=02d5

Statistics for c-kurity.blogspot.com:
Packets: sent=4, rcvd=4, error=0, lost=0 (0% loss) in 1.535975 sec
RTTs of replies in ms: min/avg/max/dev: 32.212 / 34.927 / 36.550 / 1.672
Bandwidth in kb/sec: sent=0.156, rcvd=0.156

C:\c-kurity>


Why another PING utility?

Many PING utilities are already available, one is even released with Windows itself, called PING. But there is a couple of things Windows PING doesn't offer or which are too inaccurate. That's where hrPING comes in.

So - what's the features?

Like every PING, hrPING sends "ICMP Echo Request" packets to the remote computer and listens to the matching "Echo response" packets.

The first thing that is different is that hrPING times the round trip delay in microseconds. This is done by using the CPU's "Time Stamp Counter" which is incremented with the CPU's clock cycle. You can not get any more accurate with standard PCs today!

The next thing Windows PING can not do is send more than one PING packet at a time. Windows PING always sends one packet, waits for the reply, then prints its output line, repeat.

hrPING sends out one PING packet every x milliseconds (you can adjust this time with the -s parameter) while listening for incoming replies and printing the output if there is any.

The reason why you should like this is easy: with DSL or the like you often have a delay of some 40 msec, while the upstream bandwidth of the whole connection is some 16 to 20 kbytes/sec. So, with a "standard" PING packet of 20+8+64 bytes (IP header + ICMP header + PING payload) you can send 7 packets before you get the first reply. If you want to test line conditions, thruput, etc. this "overlapped" way of sending is really helpful.

What's more, hrPING has much better statistics than Windows PING. You get the round trip times for ICMP error message replies as well! This way you can e.g. monitor the delay of a TTL exceed. hrPING counts the replies and error messages separately, so the global statistics don't mess up one another.

There's a lot more goodies hidden in hrPING, just use it and you will find out about small but useful features.


And this is how to use it:

hrPING []

may be the IP address or the hostname. In the latter case the name will be resolved to its address at the beginning of the PING loop.


There are a couple of options:

-t Ping the specified host until stopped.
Loop forever. You can abort hrPING any time with CTRL-C or CTRL-Break. Unlike Windows PING, hrPING will still print the statistics gathered so far when you abort. CTRL-C waits for some time for replies still to come in, while CTRL-Break aborts right away.

-n count Number of echo requests to send.
Specify the number of PING packets to send. Default number is 4.

-E size Stop pinging when exists
This is nice for batch files or for coordinating with a background job. hrPING will loop as long as usual (i.e. depending on -t or -n options), but will furthermore check for the existance of . If comes into existance, hrPING will exit the loop.

-l size Send buffer size (ICMP payload size).
How may bytes payload should be send? Remember that each packet is of the form: IP header (20 bytes) + ICMP header (8 bytes) + payload. You may only specify the payload size. Minimum is 0, maximum is 64k-1-20-8, i.e., 65507 bytes. Default is 64 bytes.

-L size Total IP datagram size (ICMP payload size + 28).
Same as the above, only that this size here is the size for the total IP datagram.

-f Set Don't Fragment flag in packet.
Set the "Don't fragment" bit in the IP header of the PING packet. Default is not set.

-i TTL Time To Live.
Set the "Time To Live" value in the IP header of the PING packet. Default is 255.

-v TOS Type Of Service.
Set the "Type Of Service" bits in the IP header of the PING packet. Default is 0.

-w timeout Timeout in milliseconds to wait for each reply.
Maximum timeout to wait for a reply. This is almost only of use if you switch to non-overlapped (i.e., Windows PING like) mode. In overlapped mode, this time only applies when hrPING has stopped sending (because the count was exceeded or because you pressed CTRL-C) and is waiting for missing replies. Default is 2000 milliseconds.

-s time Interval in milliseconds between packets.
This is the number of milliseconds between sending of two PING packets. hrPING will try to stick to this number very accurately. If sending took a little longer for one packet it will send out the next packet a little earlier. Default is 500 milliseconds. (You can use decimals for a very fine grained interval: -s5.4 will send a packet every 5400 microseconds, on average!)

-r Switch to traceroute mode.
hrPING contains a traceroute utility! It works almost the same as Windows TRACERT, except that it only does one test per host, not three. By default, IP addresses are not resolved to names. Use -a to do that.

-a Resolve addresses to hostnames in traceroute mode.
No need to say more.

-tsc Force RDTSC usage.
hrPING automatically decides if it uses the CPU's timestamp counter (TSC) or the operating system's performance counter for timings. On some CPU's the TSC is not reliable, since it doesn't tick at the same speed all the time. On multiprocessor systems, not all TSC have to tick exactly in sync. In almost all cases, hrPING will use the performace counter. If you want to force TSC usage, use -tsc.

-W "warm up" with one uncounted echo request at beginning
If specified, hrPING will send one uncounted ping before all others. This "warm up" is useful with some firewalls that somehow cause the first block to be much slower than the following ones.

-T Print timestamp in front of each line
Preceed each line of output with a timestamp of the form
"2006-11-22 10:55:27.201: "

-I Set ICMP id field to
Set the "Identification" IP header field to the value specified. It is possible that Windows erases or overwrites this field when sending the packet

-q Don't print a line per ping
Be quiet.

-A Abort after the first echo reply (-AA => or error)
Loop as long as there are no replies (or even error messages if -AA).

-o Don't do overlapped send/receive.
Use Windows PING like synchronous sending of one packet, waiting for the reply and so on. Off by default.

-lic Show public license and warranty.
We need you to accept the software license. This is done the first time you start hrPING. If you want to re-read it, use this option.

Return codes:

0
All sent echo requests were answered with echo replies.
1
All sent echo requests were answered with either echo replies or error messages.
2
At least some echo requests were answered with either echo replies or error messages.
9
Otherwise.

http://www.cfos.de/hrping-v310.zip
http://www.cfos.de/download/download_e.htm

Related post:

Related Posts with Thumbnails