Created
June 6, 2014 14:01
-
-
Save danielmitd/0115158a98606ea60685 to your computer and use it in GitHub Desktop.
report including network name for top ips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| TMP=$(mktemp) | |
| TMP2=$(mktemp) | |
| threshold="0.1" | |
| awk '{ split($1, b, ","); a[b[1]]++ } END { for (d in a) { printf("%d %s\n", a[d], d) } }' | sort -nr > $TMP | |
| sum=$(awk 'FNR==NR{sum+=$1;next}; END {print sum}' $TMP) | |
| while read line; do | |
| c=$(echo $line | awk '{ print $1 }') | |
| p=$(echo "$c $sum 100" | awk '{print $1/$2*$3}') | |
| if [[ $(echo "if (${p}>${threshold}) 1 else 0" | bc -l) -eq 0 ]]; then | |
| break; | |
| fi | |
| ip=$(echo $line | awk '{ print $2 }') | |
| network=$(jwhois $ip | grep -ie"net[work]*-*name" | head -n1) | |
| echo "$c,$ip,$p,$network" >> $TMP2 | |
| done < $TMP | |
| head -n25 $TMP2 | |
| echo "full list at $TMP2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment