commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Show TCP Listen ports sorted by number
(bugs: IPV6 addresses not supported)
Show If Someone Is Connected To The Android Device On And Get Their IP Address
This takes all of the tab spaces, and uses column to put them into the appropriately sized table.
IP addresses and number of connections connected to port 80.
-n NO DNS resolution or PORT/SERVICE resolution
-p PORT show
-o flag (keepalive, off, etc)
This command show listening sockets TCP and UDP. Useful for stop unwanted services from linux.
The -W switch of netstat makes it print complete URL of the connections, which otherwise by default
is truncated to fit its default column size.
Now to compensate for irregular column sizes, pipe the output to column (-t switch of column prints in tabular form). The only downside to this part is that the very first row, the header, goes pear shape.
netstat will list all open ports on the system, unix sockets, tcp sockets and udp sockets. the t flag limits to tcp ports the l flag limits to listening ports and the n flag disables the translation of port to service ( ie :25 displayed instead of :smtp ). then grep for the port you are interested in preceeded by a colon.
Same as the rest, but handle IPv6 short IPs. Also, sort in the order that you're probably looking for.
Should work with sh, bash, etc.
bit of a contrived example and playing to my OCD but nice for quick scripted output of listening ports which is sorted by port, ip address and protocol.
This has saved me many times while debugging timeout issues to "too many open files" issues. A high number of the order of thousand, indicates that somewhere connection is not being closed properly.
I used this to get all the remote connection ip addresses connected to my server... I had to start storing and tracking this data so thats why i built this out... probably not optimal as far as the egrep regex but it works ;)
Output contains also garbage (text parts from netstat's output) but it's good enough for quick check who's overloading your server.
Open Port Check
See connection's tcp timers