欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python 自動(dòng)重連wifi windows的方法

 更新時(shí)間:2018年12月18日 09:44:40   作者:light_jiang2016  
今天小編就為大家分享一篇python 自動(dòng)重連wifi windows的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

如下所示:

# coding=utf-8
import urllib2
import urllib
from cookielib import CookieJar
import os
import re
import time


class ConnectWeb(object):
 def __init__(self):
  self.cookiejarinmemory = CookieJar()
  self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejarinmemory))
  urllib2.install_opener(self.opener)
  self.username = ""
  self.password = ""

 def connect_baidu(self): #檢測(cè)目前是否聯(lián)網(wǎng)
  try:
   urllib2.urlopen("http://www.baidu.com", timeout=2)
   return 1
  except:
   return 0

 def login(self): #模擬上網(wǎng)驗(yàn)證 驗(yàn)證網(wǎng)頁(yè)幾乎都是不同的,下面附上我們學(xué)校的, form表單自己根據(jù)情況填,用chrome很容易得到post的url和表單
  try:
   post_url = ""
   form = {"action": "login", "username": self.username, "password": self.password, "ac_id": 4,
     "user_ip": "", "nas_ip": "", "user_mac": "", "save_me": 1, "ajax": 1}
   fm1 = urllib.urlencode(form)
   page = urllib2.urlopen(post_url, fm1).read()
  except Exception as e:
   self.disconnect()
   time.sleep(1)
   self.connect_wifi()

 def disconnect(self):	# 斷開wifi
  os.system("netsh wlan disconnect")

 def wifis_nearby(self):	# 查詢附近wifi
  p = os.popen("netsh wlan show all")
  content = p.read().decode("GB2312", "ignore")
  temp = re.findall(u"(SSID.*\n.*Network type.*\n.*\u8eab\u4efd\u9a8c\u8bc1.*\n.*\u52a0\u5bc6.*\n.*BSSID.*\n)",
      content)
  result = []
  for i in temp:
   name = re.findall(u"SSID.*:(.*)\n", i)[0].replace(" ", "")
   result.append(name)
  return result

 def connect_wifi(self, name=None): #連接wifi
  os.system("netsh wlan connect name=%s" % name)

 def checking(self):	# 一直檢測(cè)是否有斷網(wǎng),如果斷網(wǎng)則重新連接
  while 1:
   try:
    if not self.connect_baidu():
     self.login()
   except:
    pass
   time.sleep(10)


if __name__ == "__main__":
 test = ConnectWeb()
 test.login()

以上這篇python 自動(dòng)重連wifi windows的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論