Add to Technorati Favorites

A lot of times, I hear people asking questions like, how to find out the IP of a friend? Or how to find out your own IP? How do I know, which ports are open on my system? How do I make sure whether my system is infected with a Trojan or not?

Well, for all above questions (and more) there is one simple answer: The Netstat command.

Microsoft has this weird tendency of hiding or making sure that such ‘useful’ utilities are not easily accessible to the users. However, they fail to understand that putting a utility in the Windows directory and not listing it anywhere does not make it hidden.

The ‘Netstat’ command is accessible through the command line prompt. Simply launch MSDOS and:

C:\cd windows


NOTE: Normally, well, almost always, DOS opens by default in the Windows directory, however, for those of you whose default DOS directory is not Windows, the above would prove helpful.

Anyway, before we move on, we need to understand what exactly the Netstat command is used for. This command is by default used to get information on the open connections on your system (ports, protocols being used etc), incoming and outgoing data and also the ports of remote systems to which we are connected. ‘Netstat’ gets all this networking information by reading the kernel routing tables in the memory.

According to the RFC on Internet Tool Catalog, ‘Netstat’ is defined as:

‘Netstat is a program that accesses network related data structures within the kernel, then provides an ASCII format at the terminal. Netstat can provide reports on the routing table, TCP connections, TCP and UDP "listens", and protocol memory management.’

Anyway, now that we know what Netstat is all about, we are in a position to start using it. Once, you have launched MSDOS, you can read the MSDOS help on Netstat by giving the following command:

C:\WINDOWS>netstat /?

Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]

-a Displays all connections and listening ports. (Server-side connections are normally not shown).

-e Displays Ethernet statistics. This may be combined with the -s option.

-n Displays addresses and port numbers in numerical form.

-p proto Shows connections for the protocol specified by proto; proto may be tcp or udp. If used with the

-s option to display per-protocol statistics, proto may be tcp, udp, or ip.

-r Displays the contents of the routing table.

-s Displays per-protocol statistics. By default, statistics are shown for TCP, UDP and IP; the -p

option may be used to specify a subset of the default.

interval Redisplays selected statistics, pausing interval seconds between each display. Press CTRL+C to

stop redisplaying statistics. If omitted, netstat will print the current configuration information


However, like always, the help provided by MSDOS, can be used only as a reference, it is not at all sufficient for a complete newbie.

So, let us try out each command and see the result and also understand what exactly happens when we execute it and what all the results displayed mean.

Firstly, we will start with the Netstat command with the –a argument.

Now, the ‘–a’ option is used to display all open connections on the local machine. It also returns the remote system to which we are connected to, the port numbers of the remote system we are connected to (and the local machine) and also the type and state of connection we have with the remote system.

For Example,

C:\windows>netstat -a

Active Connections

Proto Local Address Foreign Address State


TCP ankit:1036 TIME_WAIT

TCP ankit:1043 FIN_WAIT_2

TCP ankit:1045 TIME_WAIT


TCP ankit:1053 TIME_WAIT

UDP ankit:1025 *:*

UDP ankit:nbdatagram *:*

Now, let us take a single line from the above output and see what it stands for:

Proto Local Address Foreign Address State


Now, the above can be arranged as below:

Protocol: TCP (This can be Transmission Control Protocol or TCP, User Datagram Protocol or UDP or sometimes even, IP or Internet Protocol.)

Local System Name: ankit (This is the name of the local system that you set during the Windows setup.)

Local Port opened and being used by this connection: 1031

Remote System: (This is the non-numerical form of the system to which we are connected.)

Remote Port: ftp (This is the port number of the remote system to which we are connected.)

State of Connection: ESTABLISHED

‘Netstat’ with the ‘–a’ argument is normally used, to get a list of open ports on your own system i.e. on the local system. This can be particularly useful to check and see whether your system has a Trojan installed or not. Yes, most good Antiviral software are able to detect the presence of Trojans, but, we are hackers, and need to software to tell us, whether we are infected or not. Besides, it is more fun to do something manually than to simply click on the ‘Scan’ button and let some software do it.

The following is a list of Trojans and the port numbers which they use, if you Netstat yourself and find any of the following open, then you can be pretty sure, that you are infected.

Port 12345(TCP) Netbus

Port 31337(UDP) Back Orifice

For complete list, refer to the Tutorial on Trojans at:


HACKING TRUTH: Some of you might me wondering, as to what the high port numbers after the local machine’s name stand for?

Eg. ankit:1052

Port Numbers upto 1024 normally have a specific kind of service running on it. Infact there is a complete RFC on Assigned Port Numbers- RFC 1700.

However, port numbers over 1024 are used by your system to connect to remote computers. For Example, say your browser wants to establish a connection with, then what it will do is, it will take up a random port number above 1024, open it and use it to communicate with the Hotmail server.


OK, now let us move on further, to a variant of the above command, the Netstat –n

The Netstat –n command is basically the numerical form of the Netstat –a command. The main and probably the only difference between the two is that the former shows the addresses of the local and remote systems in numerical form (Hence –n) while the latter shows the addresses in non-numerical form.

Add to My AOL Add to Google Reader or Homepage Add to netomat Hub I heart FeedBurner Subscribe in NewsGator Online Subscribe in a reader