python3 adb 获取设备序列号
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, "没有可用设备"
Python 获取设备名及地址
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();
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:- Python脚本利用adb进行手机控制的方法
- python+adb命令实现自动刷视频脚本案例
- 通过python调用adb命令对App进行性能测试方式
- python编写adb截图工具的实现源码
- 通过Python实现控制手机详解