Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- mysql_connect("", "", "");
- mysql_select_db("");
- $ips = array();
- $cts = array();
- $data = shell_exec("vzlist -H -o ctid,ip");
- $data = explode("\n", $data);
- foreach($data as $key => $value) {
- $value = trim($value);
- $value = explode(" ", $value);
- if(!empty($value[0]) && !empty($value[1])) {
- $cts[] = $value[0];
- $ips[] = $value[1];
- }
- }
- //print_r($cts);
- //print_r($ips);
- //die();
- $i = 0;
- foreach($ips as $ip) {
- $traffic = shell_exec("iptables -nvx -L FORWARD | grep '".$ip."' | tr -s [:blank:] | cut -d' ' -f3| awk '{sum+=$1} END {print sum;}'");
- mysql_query("insert into traffic(ctid, ip, measuringtime, bytes) values('".$cts[$i]."', '".$ip."', '".date("Y-m-d H:i:s")."', '".$traffic."')");
- shell_exec("iptables -D FORWARD -s ".$ip." >/dev/null 2>&1");
- shell_exec("iptables -D FORWARD -d ".$ip." >/dev/null 2>&1");
- shell_exec("iptables -A FORWARD -s ".$ip." >/dev/null 2>&1");
- shell_exec("iptables -A FORWARD -d ".$ip." >/dev/null 2>&1");
- echo "[".$cts[$i]."] ".$ip.": ".$traffic;
- $i++;
- }
- // Empty counter
- //shell_exec("iptables -Z");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment