python脚本获取当前Android流量

来源:互联网 发布:线性同余法 PHP 编辑:程序博客网 时间:2024/06/04 19:48
import time#use to control timeimport subprocessimport  osfrom color import *##############################这里要进入自己adb目录。每个人根据自己的adb 目录设置#      注意用的是反斜杠############################adb_path='C:/Users/lvbiao/Desktop/adb'os.chdir(adb_path)Uid_cmd = 'adb shell "dumpsys package com.unisound.ant.platform.hardware  | grep userId"'def getUid( ):#获取UID    p1 = subprocess.Popen(Uid_cmd, shell=True, stdout=subprocess.PIPE);    uidLongString = p1.stdout.read()    uid_info = uidLongString.decode('UTF-8','strict')     uidLongList = uid_info.split()    uidMap = uidLongList[0]    #print ("uidmap====" + uidMap )    uid= uidMap.split("=")    #print("uid1===" + uid[1])    uid =uid[1]    #print ("str is = " + uid )    return uidRev_cmd = 'adb shell "cd proc && cd uid_stat && cd '+ getUid( ) +' && cat tcp_rcv"'def getRev():#获取某个APP的TCP下载流量    p_rev = subprocess.Popen(Rev_cmd, shell=True, stdout=subprocess.PIPE);    flo_rec =int(p_rev.stdout.read())    #print ("flo_rec" + str(flo_rec))    clr.print_red_text("com.unisound.ant.platform.hardware recv Bytes ")    clr.print_red_text("RECV BYTES is =" + str(flo_rec))    clr.print_red_text("========end===========")    return flo_rec  SEN_cmd = 'adb shell "cd proc && cd uid_stat && cd '+ getUid( ) +' && cat tcp_snd"'def getSEN():#获取某个APP的TCP下载流量    p_rev = subprocess.Popen(SEN_cmd, shell=True, stdout=subprocess.PIPE);    flo_sen =int(p_rev.stdout.read())    #print ("flo_sen" + str(flo_sen))    clr.print_blue_text("========================")    clr.print_blue_text("com.unisound.ant.platform.hardware SEND Bytes ")    clr.print_blue_text("SEND BYTES is =" + str(flo_sen))    clr.print_blue_text("========end===========")    return flo_senclr = Color()   while 1:        getUid( )    time.sleep(1)    getRev()    time.sleep(1)    getSEN()    time.sleep(1)

实时监控系统收发的系统流量。监控的好工具

原创粉丝点击