check open ports (both ipv4 and ipv6)

lsof -i
This option selects the listing of all Internet and x.25 (HP-UX) network files.
Sample Output
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhclient3   817     root    5u  IPv4   3745      0t0  UDP *:bootpc 
sshd       1014     root    3u  IPv4   4770      0t0  TCP *:ssh (LISTEN)
sshd       1014     root    4u  IPv6   4772      0t0  TCP *:ssh (LISTEN)
postgres   1117 postgres    3u  IPv6   5608      0t0  TCP localhost:7175 (LISTEN)
postgres   1117 postgres    4u  IPv4   5609      0t0  TCP localhost:7175 (LISTEN)
postgres   1117 postgres    6u  IPv6   5622      0t0  UDP localhost:56982->localhost:56982 
postgres   1487 postgres    6u  IPv6   5622      0t0  UDP localhost:56982->localhost:56982 
postgres   1488 postgres    6u  IPv6   5622      0t0  UDP localhost:56982->localhost:56982 
postgres   1489 postgres    6u  IPv6   5622      0t0  UDP localhost:56982->localhost:56982 
postgres   1490 postgres    6u  IPv6   5622      0t0  UDP localhost:56982->localhost:56982 
cupsd      1539     root    5u  IPv6   5710      0t0  TCP localhost:ipp (LISTEN)
cupsd      1539     root    6u  IPv4   5711      0t0  TCP localhost:ipp (LISTEN)
sshd      27689     root    3r  IPv4  80824      0t0  TCP 172.16.221.137:ssh->vayu:59742 (ESTABLISHED)
sshd      27689     root    8u  IPv6  80950      0t0  TCP localhost:6010 (LISTEN)
sshd      27689     root    9u  IPv4  80951      0t0  TCP localhost:6010 (LISTEN)

-1
By: shsingh
2011-10-03 02:06:30

5 Alternatives + Submit Alt

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: