python編寫的adb 指令碼 (一)監控系統網速
阿新 • • 發佈:2019-01-01
import os
import time
import subprocess
import signal
import sys
root_cmd = "adb root"
os.chdir(r'C:\Users\lvbiao\Desktop\adb')
wifi_cmd = "adb shell ifstat -n -t -T 1"
iftop_cmd = "adb shell iftop"
def exit(signum, frame):
print('You choose to stop me.')
sys.exit()
signal.signal(signal.SIGINT, exit)
def wifi_status( ):
root_pipe = subprocess.Popen(root_cmd, shell=True, stdout=subprocess.PIPE).stdout;
root_info = root_pipe.read().decode();
print("===========WIFI-------------------TOTAL================")
wifi_pipe = subprocess.Popen(wifi_cmd, shell=True, stdout=subprocess.PIPE);
t = 0
while wifi_pipe.stdout.readline() != ' ':
if(t < 8):
t= t + 1
line = wifi_pipe.stdout.readline().decode('UTF-8','strict')
ine = line.strip()
print (line)
else:
break
else :
sys.exit()
print ("wifi_status process was killed" )
wifi_pipe.kill()
#activity = wifi_pipe.read();
#activity_info = activity.decode('UTF-8','strict')
#print(activity_info)
print("=======================")
def dropped_packtet( ):
print("=============== RECV Packets SEND Packets ================")
iftop_pipe = subprocess.Popen(iftop_cmd, shell=True, stdout=subprocess.PIPE);
t = 0
while iftop_pipe.stdout.readline() != ' ':
if(t < 8):
t= t + 1
line = iftop_pipe.stdout.readline().decode('UTF-8','strict')
ine = line.strip()
print (line)
else :
break
else :
sys.exit()
print ("dropped_packtet process was killed")
iftop_pipe.kill()
#activity = wifi_pipe.read();
#activity_info = activity.decode('UTF-8','strict')
#print(activity_info)
print("=======================")
while 1:
wifi_status()
time.sleep(1)
dropped_packtet()
ifstat Android裡面沒有這個命令。我自己移植 。有需要的到附件下載
附件下載