云免流量监控

    免流 泡泡 914次浏览 已收录 0个评论

    1.把下面代码放进/etc/open#v#p#n/jiankong
    2.jiankong开执行权限
    3.启动

    bash /etc/open#v#p#n/jiankong &
    

    附代码

    #!/bin/sh
    shijian=6;
    chu=1;
    chuu=1;
    localhost=数据库地址;
    root=数据库用户;
    mima=数据库密码;
    shujuku=数据库名称;
    users=user;
    user=iuser;
    isent=isent;
    irecv=irecv;
    csent=c_sent;
    crecv=c_recv;
    tcp=tcp;
    maxll=maxll;
    phone=NULL;
    jiaobenpath=$(cd `dirname $0`; pwd)
    echo  $(date +%Y年%m月%d日%k时%M分)正在清除缓存文件
    echo ${jiaobenpath}
    rm -rf ${jiaobenpath}/aa
    rm -rf ${jiaobenpath}/bb
    rm -rf ${jiaobenpath}/cc
    rm -rf ${jiaobenpath}/dd
    rm -rf ${jiaobenpath}/gg
    rm -rf ${jiaobenpath}/aa1
    rm -rf ${jiaobenpath}/bb1
    rm -rf ${jiaobenpath}/cc1
    rm -rf ${jiaobenpath}/dd1
    rm -rf ${jiaobenpath}/gg1
    echo  $(date +%Y年%m月%d日%k时%M分)开始执行流量监控...
    
    #tcp监控开始
    bmd5=$(md5sum $jiaobenpath/open#v#p#n-status.txt)
    bmd5tcp3389=$(md5sum $jiaobenpath/tcp3389.txt)
    bmd5udp138=$(md5sum $jiaobenpath/udp138.txt)
    bmd5udp53=$(md5sum $jiaobenpath/udp53.txt)
    while true
    do
    amd5=$(md5sum $jiaobenpath/open#v#p#n-status.txt)
    
    if [ "$amd5" = "$bmd5" ];
    then
    amd5=$amd5
    else
    awk -F: '$1~/[B][y][t][e][s][ ][R][e][c][e][i][v][e][d][,][B][y][t][e][s][ ][S][e][n][t]/,/[R][O][U][T][I][N][G][ ][T][A][B][L][E]/{print $0}' ''$jiaobenpath''/openvpn-status.txt | awk -F"," '{print $1 >"'$jiaobenpath'/aa"}'
    awk -F: '$1~/[B][y][t][e][s][ ][R][e][c][e][i][v][e][d][,][B][y][t][e][s][ ][S][e][n][t]/,/[R][O][U][T][I][N][G][ ][T][A][B][L][E]/{print $0}' ''$jiaobenpath''/openvpn-status.txt | awk -F"," '{print $2 }' | awk -F":" '{print $2 >"'$jiaobenpath'/bb"}'
    awk -F: '$1~/[B][y][t][e][s][ ][R][e][c][e][i][v][e][d][,][B][y][t][e][s][ ][S][e][n][t]/,/[R][O][U][T][I][N][G][ ][T][A][B][L][E]/{print $0}' ''$jiaobenpath''/openvpn-status.txt | awk -F"," '{print $3 >"'$jiaobenpath'/cc"}'
    awk -F: '$1~/[B][y][t][e][s][ ][R][e][c][e][i][v][e][d][,][B][y][t][e][s][ ][S][e][n][t]/,/[R][O][U][T][I][N][G][ ][T][A][B][L][E]/{print $0}' ''$jiaobenpath''/openvpn-status.txt | awk -F"," '{print $4 >"'$jiaobenpath'/dd"}'
    i=2
    
    until [ $i = -1 ]
    do
    aaa=$(sed -n ${i}p ${jiaobenpath}/aa)
    bbb=$(sed -n ${i}p ${jiaobenpath}/bb)
    ccc=$(sed -n ${i}p ${jiaobenpath}/cc)
    ddd=$(sed -n ${i}p ${jiaobenpath}/dd)
    
    if [ ! -n "$bbb" ];
    then
    i=-1
    else
    mysql -h$localhost -u$root -p$mima -e "use $shujuku;SELECT $isent FROM $users WHERE $user='$aaa';">>${jiaobenpath}/gg
    mysql -h$localhost -u$root -p$mima -e "use $shujuku;SELECT $irecv FROM $users WHERE $user='$aaa';">>${jiaobenpath}/gg
    mysql -h$localhost -u$root -p$mima -e "use $shujuku;SELECT $maxll FROM $users WHERE $user='$aaa';">>${jiaobenpath}/gg
    sent=$(sed -n 2p ${jiaobenpath}/gg)
    recv=$(sed -n 4p ${jiaobenpath}/gg)
    all=$(sed -n 6p ${jiaobenpath}/gg)
    rm -rf ${jiaobenpath}/gg
    let sent=$sent/$chuu
    let recv=$recv/$chuu
    let ccc=$ccc/$chu
    let ddd=$ddd/$chu
    let cccc=$sent+$ccc
    let dddd=$recv+$ddd
    let ggg=$cccc+$dddd
    #phones=NULL
    
    if [ "$phone" = "$phones" ];
    then
    phones=NULL
    sleep 1
    else
    #mysql -h$localhost -u$root -p$mima -e "use $shujuku;UPDATE $users SET $phone = '$ggg' WHERE $user='$aaa';"
    sleep 1
    fi
    
    if [ "$all" -lt "$ggg"  ];
    then
    ${jiaobenpath}/shatcp443 $aaa
    sleep 1
    echo  $(date +%Y年%m月%d日%k时%M分)成功清理超出流量TCP用户:"$aaa "
    fi
    
    i=$(( $i + 1 ))
    fi
    
    done
    #echo $i
    
    rm -rf ${jiaobenpath}/aa
    rm -rf ${jiaobenpath}/bb
    rm -rf ${jiaobenpath}/cc
    rm -rf ${jiaobenpath}/dd
    sleep 1
    fi
    
    bmd5=$(md5sum $jiaobenpath/open#v#p#n-status.txt)
    #tcp监控结束
    
    sleep $shijian
    done
    

    转载请注明云免流量监控
    喜欢 (0)
    发表我的评论
    取消评论
    表情 贴图 加粗 删除线 居中 斜体 签到

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址