python写的Android的 tcpdump 数据实时发送到wireshark

import signal
import sys 
import subprocess
import os  
import time  

global forward_status 
global adb_root
forward_cmd = "adb forward tcp:2015 tcp:2015" 
tcpdump_cmd = 'adb shell  "tcpdump -n -s 0 -w - | busybox nc -l -p 2015"'
wire_cmd = "nc 127.0.0.1 2015| wireshark -k -S -i -"

os.chdir(r'C:\Users\lvbiao\Desktop\adb')

def adb_root( ):
    os.chdir(r'C:\Users\lvbiao\Desktop\adb')
    re_forward = subprocess.call('adb root',shell=True)
    print(re_forward)
    global adb
    if re_forward ==0 :
        print('ADB root')  
        adb= 0
    else:
        adb = 1
        print('ADB  root failed ')  
        sys.exit()  
    print("=======================")


def exit(signum, frame):  
    print('You choose to stop me.')  
    #fhandle.close();
    sys.exit()  
def forward( ):
    os.chdir(r'C:\Users\lvbiao\Desktop\adb')
    re_forward = subprocess.call(forward_cmd,shell=True)
    global forward_status 
    print(re_forward)
    if re_forward ==0 :
        forward_status= 0
    else:
        forward_status = 1
        print('ADB NOT CONNECT')  
        sys.exit()  
    print("=======================")


def tcpdump():
    print("======start tcpdump=======")
    os.chdir(r'C:\Users\lvbiao\Desktop\adb')
    tcpdump_pipe = subprocess.Popen(tcpdump_cmd, shell=True, stdout=subprocess.PIPE).stdout;
'''
    while wifi_pipe.readline() != ' ':
        line = tcpdump_pipe.readline().decode('UTF-8','strict')
        #line = line.strip()
        fhandle.write(line)
        print (line)
    else :
        sys.exit()

    print("=======================")    
'''
def open_Wireshark():
    os.chdir(r'D:\Wireshark')
    print("======start wire=======")
    wire_pipe = subprocess.Popen(wire_cmd, shell=True, stdout=subprocess.PIPE).stdout;
'''
    while wifi_pipe.readline() != ' ':
        line = tcpdump_pipe.readline().decode('UTF-8','strict')
        #line = line.strip()
        fhandle.write(line)
        print (line)
    else :
        sys.exit()
'''


adb_root( )
forward()
tcpdump()
time.sleep(2)
open_Wireshark()

只要打开这个脚本就会主动连接adb connect Android设备。并执行tcpdump 数据发送到pc 端的wireshark 。 实时数据传送。相当方便
这里面需要的nc可以到我附件下载 不懂的可以留言
nc工具下载
如果想下载Wireshark 的
Wireshark

猜你喜欢

转载自blog.csdn.net/lb5761311/article/details/77967028