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:
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
Count on a specific port (80) - FreeBSD friendly.
This obtains a list of open connections that a user is connected to if he/she is using a SSH tunnel
cut -f1,2 - IP range 16
cut -f1,2,3 - IP range 24
cut -f1,2,3,4 - IP range 24
Show state of NAT, readed from '/proc/net/ip_conntrack' or '/proc/net/nf_conntrack'
See who is using a specific port. Especially when you're using AIX. In Ubuntu, for example, this can easily be seen with the netstat command.
This is also perl-less, and only uses AWK as its postprocessor. Tested with GAWK and MAWK.
if you don't do --numeric-ports, netstat will try to resolve them to names
Easy to remenber. Fot TCP only use: netstat -plant
Lists all opened sockets (not only listeners), no DNS resolution (so it's fast), the process id and the user holding the socket.
Previous samples were limiting to TCP too, this also lists UDP listeners.
Check open TCP and UDP ports
While `lsof` will work, why not use the tool designed explicitly for this job?
(If not run as root, you will only see the names of PID you own)
shell loop to scan netstat output avoiding loolback aliases (local/remote swap for local connections)
We use the "convert" command (ImageMagick package) : see man convert (http://www.ma.utexas.edu/cgi-bin/man-cgi?convert+1)
Count and Find all IP connected to my host through TCP connection.