One-liner to count current IP connections

A quick one-liner to show the IP addresses with an established connection to your server, sorted in order:

netstat -ant | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr

If you care only about a certain TCP port, say 80 for web traffic, the command becomes:

netstat -ant | grep :80 | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr

Output would look like:


36 14.21.23.10
8 14.21.23.107
7 14.21.23.114
6 14.21.2.34
5 14.21.23.108
5 14.21.23.106
5
2 14.21.13.120
1 14.21.2.23
1 14.21.13.147
1 14.21.13.130
1 14.21.13.128
1 14.21.13.122
1 14.21.13.118
1 14.21.13.112

Continue reading “One-liner to count current IP connections”

vim replace with newline

Just a quick vi/vim tip that I’d never had to do before now.

Scenario: a file with multiple lines, each terminated with a semicolon, that needed to be broken out into separate lines for easier reading.

Solution:

In vim, use \r in the search-and-replace command to indicate a new line:

:%s/;/;\r/g

Email forwarding to multiple recipients with cPanel

At first I thought I’d have to do something complicated like an email list. But I found out that you just have to create multiple single forwarder entries with the same “Address to forward” for each, and the different recipients in each “Forward to email address” field per entry.

Example:


boardofdirectors@example.com -> joe.blow@example.net
boardofdirectors@example.com -> jane.smith@example.org