Skip to content

Commit

Permalink
Added: iptables traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Dec 16, 2018
1 parent 964f3ba commit 1a5059f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions global_setting/calcul_traffic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
PORT=$1

INPUT_TRAFFIC=$(iptables -nvL INPUT -x|grep $PORT|awk '{sum += $2};END {printf("%.0f\n",sum)}')

OUTPUT_TRAFFIC=$(iptables -nvL OUTPUT -x|grep $PORT|awk '{sum += $2};END {printf("%.0f\n",sum)}')

if [[ $INPUT_TRAFFIC && $OUTPUT_TRAFFIC ]]; then
TOTAL_TRAFFIC=`expr $INPUT_TRAFFIC + $OUTPUT_TRAFFIC`
echo "$INPUT_TRAFFIC $OUTPUT_TRAFFIC $TOTAL_TRAFFIC"
fi
4 changes: 2 additions & 2 deletions multi-v2ray.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ profileInit() {
fi

bash $APP_PATH/global_setting/clean_iptables.sh

echo -e "生成$(colorEcho $BLUE iptables)流量统计规则中.."
echo ""
echo -e "生成 $(colorEcho $BLUE iptables) 流量统计规则中.."
python3 -c "from utils import open_port; open_port();"
}

Expand Down
6 changes: 6 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def gen_cert(domain):
for name in service_name:
os.system(start_cmd.format(name))

def calcul_iptables_traffic(port):
traffic_result = os.popen("bash /usr/local/multi-v2ray/global_setting/calcul_traffic.sh {}".format(str(port))).readlines()
if traffic_result:
traffic_list = traffic_result[0].split()
return [bytes_2_human_readable(traffic_list[0]), bytes_2_human_readable(traffic_list[1]), bytes_2_human_readable(traffic_list[2])]

def clean_iptables(port):
clean_cmd = "iptables -D {0} {1}"
check_cmd = "iptables -nvL %s --line-number|grep -w \"%s\"|awk '{print $1}'|sort -r"
Expand Down

0 comments on commit 1a5059f

Please sign in to comment.