Awk View the number of ip connections (common application one)

  

Processing text is a strong point of awk. No matter how fast the performance is, it’s amazing!

[chengmo@localhost ~]$ awk 'BEGIN{ while("netstat -an"| Getline){ if( $5 ~ /[1-255]/) { split($5,t1,":"); tarr[t1[1]]++; } } for(k in tarr) { print k ,tarr[k] |  "sort -r -n -k2"; }};'

$5 is netstat –an 5th field. The default is the other party's connection ip and port.


[chengmo@localhost ~]$ time awk 'BEGIN{while("netstat -an"| Getline){if( $5 ~ /[1-255]/){split($5,t1,":");tarr[t1[1]]++;}}for(k in tarr){print k ,tarr[k] |  "sort -r -n -k2";}};' 211.151.33.14 28113.65.21.200 14121.32.89.106 1360.191.178.230 12118.133.177.104 1258.61.152.154 11219.137.58.20 11124.117.248.52 11122.198.80.145 11222.88.15.138 10222.44.13.191 10222.161. 47.34 10221.4.202.210 10218.79.64.12 10183.17.92.193 10120.72.128.254 10118.118.121.244 10116.252.38.236 10113.248.75.44 10


real 0m1.149suser 0m0.032ssys 0m1.055s


Awk common application series, will always be updated! I will summarize some of my code in server management over the years to learn from my friends.

Copyright © Windows knowledge All Rights Reserved