python编写的adb 脚本 (一)监控系统网速

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里面没有这个命令。我自己移植 。有需要的到附件下载
附件下载

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九霄的爸爸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值