python3 adb 獲取設(shè)備序列號(hào)
import subprocess
def deal_cmd(cmd):
pi = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
# print(pi.stdin.read())
return pi.stdout.read()
def deal_result():
result = deal_cmd('adb devices')
result = result.decode("utf-8")
if result.startswith('List of devices attached'):
# 查看連接設(shè)備
result = result.strip().splitlines()
# 查看連接設(shè)備數(shù)量
device_size = len(result)
if device_size > 1:
device_list = []
for i in range(1, device_size):
device_detail = result[1].split('\t')
if device_detail[1] == 'device':
device_list.append(device_detail[0])
elif device_detail[1] == 'offline':
print(device_detail[0])
return False, '連接出現(xiàn)異常,設(shè)備無(wú)響應(yīng)'
elif device_detail[1] == 'unknown':
print(device_detail[0])
return False, '沒(méi)有連接設(shè)備'
return True, device_list
else:
return False, "沒(méi)有可用設(shè)備"
Python 獲取設(shè)備名及地址
1. 查詢(xún)本機(jī)的設(shè)備名及IP地址,打開(kāi)Python 3.6(32-bit),輸入:
import socket
host_name = socket.gethostname()
print(" Host name: %s" %host_name)
print(" IP address: %s" %socket.gethostbyname(host_name))
2. 查詢(xún)本地的設(shè)備名及IP地址,使用內(nèi)置的類(lèi)方法,定義成一個(gè)獨(dú)立的函數(shù)print_device_info()
import socket
def print_device_info():
host_name = socket.gethostname()
print(" Host name: %s" %host_name)
print(" IP address: %s" %socket.gethostbyname(host_name))
if __name__=='__main__':
print_device_info();
3. 查詢(xún)遠(yuǎn)程設(shè)備名及IP地址,定義一個(gè)函數(shù)print_device_remote_info()
import socket
def print_device_remote_info():
host_name = 'home.lenovo'
print(" Host name: %s" %host_name)
print(" IP address: %s" %socket.gethostbyname(host_name))
if __name__=='__main__':
print_device_remote_info();
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- Python腳本利用adb進(jìn)行手機(jī)控制的方法
- python+adb命令實(shí)現(xiàn)自動(dòng)刷視頻腳本案例
- 通過(guò)python調(diào)用adb命令對(duì)App進(jìn)行性能測(cè)試方式
- python編寫(xiě)adb截圖工具的實(shí)現(xiàn)源碼
- 通過(guò)Python實(shí)現(xiàn)控制手機(jī)詳解