不連線usb對手機進行操作(設定步驟)
阿新 • • 發佈:2018-11-09
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()