运维开发网
广告位招商联系QQ:123077622
 
广告位招商联系QQ:123077622

python3 adb 获取设备序列号的实现

运维开发网 https://www.qedev.com 2021-06-04 11:06 出处:网络 作者: 云梦九章
python3 adb 获取设备序列号 import subprocess def deal_cmd(cmd): pi = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

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))

python3 adb 获取设备序列号的实现

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))
iSUzLFjkQuf  __name__=='__main__':
      print_device_info();

python3 adb 获取设备序列号的实现

3. 查询远程设备名及IP地址,定义一个函数print_device_remote_info()

import  socket
def  print_device_remote_info():
      host_name = 'home.lenovo'
      prinhttp://www.cppcns.comt(" Host name: %s"  %host_name)
      print(" IP address: %s"  %socket.gethostbyname(host_name))
if  __name__=='__main__':
      print_device_remote_info();

python3 adb 获取设备序列号的实现

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消