不连接usb对手机进行操作(设置步骤)

import subprocess
import re

#1.电脑和手机连接的wifi处于同一个网段;2.手机连接usb后运行脚本。断开usb可继续操作手机

class Connection(object):
    def connect_adb_tcpip(self):
        adb_tcpip=subprocess.Popen('adb tcpip 5555',stdout=subprocess.PIPE,stdin=subprocess.PIPE)
        adb_tcpip.stdout.read()

    def connect_adb_netcfg(self):
        adb_netcfg=subprocess.Popen('adb shell netcfg',stdout=subprocess.PIPE,stdin=subprocess.PIPE)
        phone_ip=re.findall(r'wlan0    UP *(\d+.\d+.\d+.\d+)/',str(adb_netcfg.stdout.read(),'utf-8').strip())
        return phone_ip[0]

    def connect_phone(self):
        connect_phone=subprocess.Popen('adb connect '+self.connect_adb_netcfg()+':5555',stdout=subprocess.PIPE,stdin=subprocess.PIPE)
        connect_phone.stdout.read()

if __name__=='__main__':
    S=Connection()
    #S.connect_adb_tcpip()
    S.connect_phone()

 

你可能感兴趣的:(python)