帝王 发表于 2018-8-27 06:19:36

shell统计当前网络连接情况

# cat account_tcp.sh  
#!/bin/bash
  
#统计当前网络连接情况
  
netstat -na | awk '/^tcp/{s[$6]++}END{for(key in s)print key,s}' > /root/account_tcp/state.txt
  
#统计Local Address的TCP连接数
  
netstat -na | awk '/^tcp/' | awk -v FS="[ :]+" '{print $4}' | sort | uniq -c | sort -n > /root/account_tcp/Local_Address.txt
  
#统计IP为51的Foreign Address的TCP连接情况
  
netstat -na | awk '/^tcp/' | grep 192.168.10.51 | awk -v FS="[ :]+" '{print $6}' | sort | uniq -c | sort -n > /root/account_tcp/51_tcp.txt
  
#统计IP为80的Foreign Address的TCP连接情况
  
netstat -na | awk '/^tcp/' | grep 192.168.10.80 | awk -v FS="[ :]+" '{print $6}' | sort | uniq -c | sort -n > /root/account_tcp/80_tcp.txt
  
#统计IP为86的Foreign Address的TCP连接情况
  
netstat -na | awk '/^tcp/' | grep 192.168.10.86 | awk -v FS="[ :]+" '{print $6}' | sort | uniq -c | sort -n > /root/account_tcp/86_tcp.txt
  
#统计IP为87的Foreign Address的TCP连接情况
  
netstat -na | awk '/^tcp/' | grep 192.168.10.87 | awk -v FS="[ :]+" '{print $6}' | sort | uniq -c | sort -n > /root/account_tcp/87_tcp.txt


页: [1]
查看完整版本: shell统计当前网络连接情况