Skip to content

Instantly share code, notes, and snippets.

@yourtion
Created May 23, 2017 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yourtion/067b99589858b7a70eea96ef854dd99b to your computer and use it in GitHub Desktop.
Save yourtion/067b99589858b7a70eea96ef854dd99b to your computer and use it in GitHub Desktop.
#!/bin/sh
# monit add : iptables -I OUTPUT -s 你的服务器IP -p tcp --sport 开放的端口
# show : iptables -n -v -L -t filter
#统计流量
flowname="/data/log/vpn/flow.log"
flownametail="/data/log/vpn/flow_tail.log"
flowregex="spt:端口起始到结尾"
date +"[%Y-%m-%d %H:%M:%S]" >> $flowname
iptables -n -v -L -t filter | egrep $flowregex | awk -F ' ' '{print $10 "\t" $2}' >> $flowname
iptables -n -v -L -t filter | egrep $flowregex | awk -F ' ' '{print $10 "\t" $2}' > $flownametail
#!/bin/sh
# add to cron : * * * * * /home/shadowsocks/monitor.sh
#当前使用统计
filename="/data/log/vpn/monitor.log"
regex="你开放的端口起始与结尾"
date +"[%Y-%m-%d %H:%M:%S]" >> $filename
netstat -anp | egrep $regex | grep -E "tcp.*ESTABLISHED" | awk '{print $4, $5}' | cut -d: -f2 | sort -u >> $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment