思路:通过adb命令开关wifi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
class Wifi():
def __init__(self,count):
self.count = count
# 开启wifi的方法
def openWifi(self):
cmd = 'adb shell svc wifi enable'
os.popen(cmd)
time.sleep(10)
# 关闭wifi的方法
def closeWifi(self):
cmd = 'adb shell svc wifi disable'
os.popen(cmd)
time.sleep(10)
#获取wifi当前开关状态
def getWifiStatue(self):
cmd='adb shell settings get global wifi_on'
f = os.popen(cmd)
str = f.readlines()
if( str == ['1\n']):
print("wifi成功开启")
elif(str == ['0\n']):
print("wifi成功关闭")
else:
print('wifi出错了')
#控制wifi循环的方法
def controlWifi(self):
i = 1
while (self.count >0):
print("第 %d 次执行关闭Wi-Fi操作:" % i)
self.closeWifi()
self.getWifiStatue()
print("第 %d 次执行开启Wi-Fi操作:" % i)
self.openW