Python 官方文档:入门教程 => 点击学习
python3 adb 获取设备序列号 import subprocess def deal_cmd(cmd): pi = subprocess.Popen(cmd, shel
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'):
# 查看连接设备
result = result.strip().splitlines()
# 查看连接设备数量
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, '连接出现异常,设备无响应'
elif device_detail[1] == 'unknown':
print(device_detail[0])
return False, '没有连接设备'
return True, device_list
else:
return False, "没有可用设备"
1. 查询本机的设备名及IP地址,打开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. 查询本地的设备名及IP地址,使用内置的类方法,定义成一个独立的函数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. 查询远程设备名及IP地址,定义一个函数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();
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: python3 adb 获取设备序列号的实现
本文链接: https://lsjlt.com/news/127539.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0