Questions tagged [netstat]

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.

netstat

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.

Parameters

Parameters used with this command must be prefixed with a hyphen (-) rather than a slash (/).

  • -a : Displays all active connections and the TCP and UDP ports on which the computer is listening.
  • -b : Displays the binary (executable) program's name involved in creating each connection or listening port. (Windows XP, 2003 Server and newer Windows operating systems (not Microsoft Windows 2000 or other non-Windows operating systems)) On Mac OS X when combined with -i, the total number of bytes of traffic will be reported.
  • -e : Displays ethernet statistics, such as the number of bytes and packets sent and received. This parameter can be combined with -s.
  • -f : Displays fully qualified domain names for foreign addresses (only available on Windows Vista and newer operating systems).
  • -g : Displays multicast group membership information for both IPv4 and IPv6 (may only be available on newer operating systems)
  • -i : Displays network interfaces and their statistics (not available under Windows)
  • -m : Displays the STREAMS statistics.
  • -n : Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names.
  • -o : Displays active TCP connections and includes the process ID (PID) for each connection. You can find the application based on the PID on the Processes tab in Windows Task Manager. This parameter can be combined with -a, -n, and -p. This parameter is available on Microsoft Windows XP, 2003 Server (and Windows 2000 if a hotfix is applied).[2]
  • -p Windows and BSD: Protocol : Shows connections for the protocol specified by Protocol. In this case, the Protocol can be tcp, udp, tcpv6, or udpv6. If this parameter is used with -s to display statistics by protocol, Protocol can be tcp, udp, icmp, ip, tcpv6, udpv6, icmpv6, or ipv6.
  • -p Linux: Process : Show which processes are using which sockets (similar to -b under Windows) (you must be root to do this)
  • -P Solaris: Protocol : Shows connections for the protocol specified by Protocol. In this case, the Protocol can be ip, ipv6, icmp, icmpv6, igmp, udp, tcp, or rawip.
  • -r : Displays the contents of the IP routing table. (This is equivalent to the route print command under Windows.)
  • -s : Displays statistics by protocol. By default, statistics are shown for the TCP, UDP, ICMP, and IP protocols. If the IPv6 protocol for Windows XP is installed, statistics are shown for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6 protocols. The -p parameter can be used to specify a set of protocols.
  • -t Linux: Displays only TCP connections.
  • -v : When used in conjunction with -b it will display the sequence of components involved in creating the connection or listening port for all executables.
  • Interval : Redisplays the selected information every Interval seconds. Press CTRL+C to stop the redisplay. If this parameter is omitted, netstat prints the selected information only once.
  • -h (unix) /? (windows): Displays help at the command prompt.

Statistics Provided

Netstat provides statistics for the following:

Protocol - The name of the protocol (TCP or UDP).

Local Address - The IP address of the local computer and the port number being used. The name of the local computer that corresponds to the IP address and the name of the port is shown unless the -n parameter is specified. If the port is not yet established, the port number is shown as an asterisk (*).

Foreign Address - The IP address and port number of the remote computer to which the socket is connected. The names that corresponds to the IP address and the port are shown unless the -n parameter is specified. If the port is not yet established, the port number is shown as an asterisk (*).

State - Indicates the state of a TCP connection. The possible states are as follows: CLOSE_WAIT, CLOSED, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, LAST_ACK, LISTEN, SYN_RECEIVED, SYN_SEND, and TIME_WAIT. For more information about the states of a TCP connection, see RFC 793.

Examples

To display the statistics for only the TCP or UDP protocols, type one of the following commands:

netstat -sp tcp
netstat -sp udp

To display active TCP connections and the process IDs every 5 seconds, type the following command (On Microsoft Windows, works on XP and 2003 only, or Windows 2000 with hotfix):

netstat -o 5

Mac OS X version:

netstat -w 5

To display active TCP connections and the process IDs using numerical form, type the following command (On Microsoft Windows, works on XP and 2003 only, or Windows 2000 with hotfix):

netstat -no

To display all ports open by a process with id pid:

netstat -aop | grep "pid"

Platform specific remarks

On the Windows platform, netstat information can be retrieved by calling the GetTcpTable and GetUdpTable functions in the IP Helper API, or IPHLPAPI.DLL. Information returned includes local and remote IP addresses, local and remote ports, and (for GetTcpTable) TCP status codes. In addition to the command-line netstat.exe tool that ships with Windows, GUI-based netstat programs are available.

On the Windows platform, this command is available only if the Internet Protocol (TCP/IP) protocol is installed as a component in the properties of a network adapter in Network Connections.

On Mac OS X 10.5, the above option "-o" is not available. With Mac OS X 10.5, the /Applications/Utilities folder contains a network utility called: Network Utility, see tab Netstat for these stats presented in a gui application, along with Ping, Lookup, Traceroute, Whois, Finger and Port Scan.

Wikipedia Entry for netstat

548 questions
0
votes
1 answer

java programs are displaying as SYSTEMin netstat -b results

I am running same java application on two servers. Applications are deployed using TOMCAT. When I verify using netstat -b to check whether its running properly or not, I can see that netstat results is showing SYSTEM instead of java.exe process in…
0
votes
0 answers

Weird CLOSE_WAIT statuses at standard PHP application

I have a Web application built in PHP. The client is a standard html/js page viewed in the web browser. This client sends Ajax requests every minute to get its updates. This setup worked the same way since two years. The logs tell me that one user…
dboth
  • 97
  • 1
  • 9
0
votes
2 answers

trying to pass from hex(base 16) to dec to ip6 /proc/net/tcp6

im reading the content of the file /proc/net/tcp6 and trying to transform that notation of ip6 into a '0::1' like previously with ipv4 y use the next method. struct sockaddr_in tmp_ip; char ip_str[30]; char ipex[]='00000AF0'; /*read from the file…
Freaktor
  • 700
  • 1
  • 10
  • 21
0
votes
1 answer

Filter network packet by process PID with libpcap

Im trying to analyze traffic network using libpcap in C language. I would like to filter packets by process PID. I've been doing research and apparantly pcap can't do what I want but netstat can give me information about traffic with process pid.…
Mistrale
  • 153
  • 1
  • 1
  • 5
0
votes
2 answers

Behind AWS ELB : How to grab the Real IP from "netstat"?

I'm using AWS Elastic Load Balancing (ELB) in front of 2 Linux Web Servers. But (based on my requirement) i need to know the Real IPs from the Web Servers' perspective, especially when i use netstat. I need to know the number of incoming connections…
夏期劇場
  • 17,821
  • 44
  • 135
  • 217
0
votes
1 answer

list of tcp connections for particular port

I need list of tcp connections made where client has particular port for example : from my linux server need to check if any connection is made with client by 8008 port of client within last two minutes.. Is this possible or I m looking for too…
raheem52
  • 486
  • 1
  • 7
  • 18
0
votes
1 answer

AHK Script GUI & Netstat update delay

I've gone into creating Autohotkey Script GUIs out of interest. I made a diagnostic tool of sorts, and one function of this tool is to give the user a constant, live update on their download speed in Kbps and Mbps using the netstat command. I…
0
votes
1 answer

Find process using port 80

I have a Windows service that listens on port 80 using OWIN self hosting (WebApp.Start). I want to find that service programmatically using a PowerShell script. I have the following PowerShell script: netstat -noab | Select-String ":80 "…
Jeff
  • 35,755
  • 15
  • 108
  • 220
0
votes
0 answers

Terminal Server logon script

I'm writing a simple .bat script to track logons to our terminal servers and append the records to a single CSV file. I can't quite get my script to behave correctly. Almost everything is working, but the clientip variable has an entire line of…
0
votes
1 answer

Python Script to view "netstat" command periodically and print any changes in different outputs?

I am writing a python Script to view "netstat" command output periodically and save it to a file. In case any port changes are there between different outputs of netstat.Print those lines to another file and save. Sample output of netstat…
Krishna
  • 45
  • 2
  • 6
0
votes
0 answers

IBM AIX collect real-time network statistics programmatically without indefinite polling

I need to collect network statistics in IBM AIX in real-time programmatically. Specifically the number of bytes transmitted (TX) and received (RX) Searched the web and found few ways which are all using the shell commands like netstat, entstat,…
Dinesh
  • 1,825
  • 5
  • 31
  • 40
0
votes
1 answer

How to sum first Column on netstat result

I want to count the packets of an interface like ix1 . The result of netstat -I ix1 -w1 is something like this . input (ix1) output packets errs idrops bytes packets errs bytes colls 0 0 0 …
sam
  • 1,363
  • 1
  • 20
  • 32
0
votes
1 answer

How to Show specific interface Statistics with netstat

I want to show statistics of each interface . netstat -w1 shows good result and netstat -i shows interface names . But I can not combine this 2 options . for example netstat -i ix1 -w1 dos not show only the ix1 interface statistics What should…
sam
  • 1,363
  • 1
  • 20
  • 32
0
votes
1 answer

How to find out what program is listing to port 80 on windows?

I am having issue when attempting to start XAMPP on port 80 because port 80 is being used by another service. I don't want to change the default port to XAMPP. I need to find out what service is using port 80 and stop it. I tried this…
Jaylen
  • 39,043
  • 40
  • 128
  • 221
0
votes
1 answer

How to use route to make a protocol specific route

BSD/MacOS X has a command "route" for altering the system routing table. One of the options that it supports is -proto1 (as well as proto2/proto3) which are for setting a route to be protocol specific. I am wanting to use this to set a route that is…
brant
  • 369
  • 3
  • 8