lsof -i; list information about Internet and network files

I talked to a person on IRC, who had a problem with his computer spamming his service provider with UDP packets. He solved his problem by using lsof -i, which lists information about Internet and network files.

Using more options for the -i parameter can give a more specific list of information.


                [46][protocol][@hostname|hostaddr][:service|port]

                where:
                     46 specifies the IP version, IPv4 or IPv6
                          that applies to the following address.
                          ’6’ may be be specified only if the UNIX
                          dialect supports IPv6.  If neither ’4’ nor
                          ’6’ is specified, the following address
                          applies to all IP versions.
                     protocol is a protocol name - TCP or UDP.
                     hostname is an Internet host name.  Unless a
                          specific IP version is specified, open
                          network files associated with host names
                          of all versions will be selected.
                     hostaddr is a numeric Internet IPv4 address in
                          dot form; or an IPv6 numeric address in
                          colon form, enclosed in brackets, if the
                          UNIX dialect supports IPv6.  When an IP
                          version is selected, only its numeric
                          addresses may be specified.
                     service is an /etc/services name - e.g., smtp -
                          or a list of them.
                     port is a port number, or a list of them.

Here is a sample:


tomasz@arcadia ~ $ lsof -i
COMMAND  PID   USER   FD   TYPE DEVICE SIZE NODE NAME
xchat   5362 tomasz   10u  IPv4  22056       TCP 192.168.1.107:54186->censored.dk:ircd (ESTABLISHED)
xchat   5362 tomasz   15u  IPv4  22063       TCP 192.168.1.107:47961->springtide.springtide.ca:ircd (ESTABLISHED)
xchat   5362 tomasz   20u  IPv4  22070       TCP 192.168.1.107:38401->underworld.rizon.no:6697 (ESTABLISHED)
xchat   5362 tomasz   25u  IPv4  22077       TCP 192.168.1.107:45011->efnet.pte.hu:9999 (ESTABLISHED)
xchat   5362 tomasz   30u  IPv4  22084       TCP 192.168.1.107:59340->jobe.wgops.com:ircd (ESTABLISHED)
pidgin  5372 tomasz   11u  IPv4  22337       TCP 192.168.1.107:60255->by1msg2175306.phx.gbl:1863 (ESTABLISHED)
pidgin  5372 tomasz   12u  IPv4  22298       TCP 192.168.1.107:45727->2605ds1-ynoe.1.fullrate.dk:xmpp-client (ESTABLISHED)
pidgin  5372 tomasz   16u  IPv4 168971       TCP 192.168.1.107:41941->by2msg2132817.phx.gbl:1863 (ESTABLISHED)
pidgin  5372 tomasz   17u  IPv4 168311       TCP 192.168.1.107:59297->by2msg1231704.phx.gbl:1863 (ESTABLISHED)

lsof can not only list information about Internet and network files, but list file information opened by processes and help solving problems in general. Just wanted you to know this cool application.

Post a comment.