示例#1
0
def CrackWifi(password):
    wifi = pywifi.PyWiFi()
    iface = wifi.interfaces()[0] # 取一个无限网卡
    # 是否成功的标志
    isok = True

    if(iface.status()!=const.IFACE_CONNECTED):
      profile = pywifi.Profile()
      profile.ssid = SSID
      profile.auth = const.AUTH_ALG_OPEN     #需要秘密
      profile.akm.append(const.AKM_TYPE_WPA2PSK) #加密类型
      profile.cipher = const.CIPHER_TYPE_CCMP   #加密单元
      #profile.key = '123456789'         #在此输入你的wifi密码
      profile.key = password
      #time.sleep(3)
      wifi = pywifi.PyWiFi()
      iface = wifi.interfaces()[0] # 取一个无限网卡
      profile = iface.add_network_profile(profile)
      iface.connect(profile)
      time.sleep(3)    #程序休眠时间3秒;如果没有此句,则会打印连接失败,因为它需要一定的检测时间
      if iface.status()==const.IFACE_CONNECTED:
        print("连接成功!!!")
      else:
        print("连接失败!!!")
        isok=False
      return isok
    else:
      print("已经连接网络")
      return isok
示例#2
0
 def __init__(self):
     if platform.system().lower() == 'windows':
         self._iface = pywifi.PyWiFi().interfaces()[0]
     elif platform.system().lower() == 'linux':
         self._iface = pywifi.PyWiFi().interfaces()[0]
     else:
         self._iface = None
     self._profile = None
示例#3
0
def test_wifi_connect(passwordstr):
    wifi = pywifi.PyWiFi()  #初始化
    ifaces = wifi.interfaces()[0]  #创建取出第一个无限网卡
    # print(ifaces.name())#输出无限网卡名
    ifaces.disconnect()  #断开无限网卡连接
    time.sleep(3)  #断开以后缓冲3秒

    profile = pywifi.Profile()  #配置文件
    profile.ssid = "TP-LINK_168"  #wifi名称
    profile.auth = const.AUTH_ALG_OPEN  #需要密码连接
    profile.akm.append(const.AKM_TYPE_WPA2PSK)  #wifi加密
    profile.cipher = const.CIPHER_TYPE_CCMP  #机密单元
    profile.key = passwordstr  #wifi密钥

    ifaces.remove_all_network_profiles()  #删除其他所有配置文件
    tmp_profile = ifaces.add_network_profile(profile)  #加载配置文件

    ifaces.connect(tmp_profile)  #连接
    time.sleep(10)  #10秒内能否连接上
    isok = True
    if ifaces.status() == const.IFACE_CONNECTED:
        print("连接成功")
    else:
        print("连接失败")

        ifaces.disconnect()  #断开连接
        time.sleep(1)

    return isok
示例#4
0
def wificonnect(str, wifiName):
    # 创建一个无线对象
    wifi = pywifi.PyWiFi()
    # 获取第一个无线网卡
    ifaces = wifi.interfaces()[0]
    # 断开所有WiFi
    ifaces.disconnnect()
    time.sleep(1)
    if ifaces.status() == const.IFACE_DISCONNECTED:
        # 创建WiFi连接文件
        profile = pywifi.Profile
        profile.ssid = wifiName
        # WiFi加密算法
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        # wifi密码
        profile.key = str
        # 网卡的开放状态
        profile.auth = const.AUTH_ALG_OPEN
        # 删除所有的WiFi连接文件
        ifaces.remove_all_network_profile()
        # 设定新的连接文件
        tep_profile = ifaces.add_network_profile(profile)
        ifaces.connect(tep_profile)
        time.sleep(5)
        if ifaces.status == const.IFACE_CONNECTED:
            return True
        else:
            return False
    if ifaces.status() == const.IFACE_CONNECTED:
        print('已经连接')
示例#5
0
def test_connect(password_str):
    wifi = pywifi.PyWiFi()  # 开启一个无线对象
    interface = wifi.interfaces()[0]  # 抓取无线网卡列表第一个无线网卡
    # print(wifi.interfaces())
    # print(interface.name())  # 取出无限网卡的名字

    interface.disconnect()  # 断开无线网卡连接
    time.sleep(3)  # 断开以后缓冲3秒

    profile = pywifi.Profile()  # 配置文件
    profile.ssid = "ACFUN"  # 就是wifi名称
    profile.auth = const.AUTH_ALG_OPEN  # 需要密码链接
    profile.akm.append(const.AKM_TYPE_WPA2PSK)  # wifi加密算法
    profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
    profile.key = password_str  # 测试密码成功或者失败

    interface.remove_all_network_profiles()  # 删除其他所有配置文件
    tmp_profile = interface.add_network_profile(profile)  # 加载配置文件

    interface.connect(tmp_profile)  # 连接
    time.sleep(5)  # 5秒内看是否可以链接上。
    isok = False  # 标识连接成功状态,初值为连接失败

    if interface.status() == const.IFACE_CONNECTED:  # 连接成功
        isok = True
        print("%s 连接成功,密码是:%s" % (profile.ssid, password_str))
    else:
        print("%s 连接失败,密码是:%s" % (profile.ssid, password_str))

    interface.disconnect()  # 断开连接
    time.sleep(1)
    return isok
示例#6
0
def start_crack_wifi():
    password = ""
    profile = scan_wifi()
    # print(profile.ssid,profile.akm,profile.auth,profile.key)
    # read password_text
    print("  start!  ")
    # read only
    with open('E:/password.txt', 'r+') as pw_file:
        temp_pw = pw_file.readline()
        num = 1
        while temp_pw:
            # print(" test password %s " %(temp_pw))
            profile.key = temp_pw
            wifi = pywifi.PyWiFi()
            iface = wifi.interfaces()[0]
            temp_profile = iface.add_network_profile(profile)
            iface.connect(temp_profile)
            time.sleep(3)
            if iface.status() == const.IFACE_CONNECTED:
                password = temp_pw
                with open('E:/result.txt', 'a+') as re_file:
                    re_file.write('wifi:%s-------pw:%s \r' %
                                  (profile.ssid, password))
                re_file.close()
                break
            else:
                print("the %d test: No!  %s " % (num, temp_pw))
                num += 1
            temp_pw = pw_file.readline()
    pw_file.close()
    return password
示例#7
0
def Scan():
    wifi = pywifi.PyWiFi()
    interface = wifi.interfaces()[0]
    interface.scan()
    ssids_scan_result = interface.scan_results()
    for ssid in ssids_scan_result:
        print(ssid.ssid)
示例#8
0
def info():
    iwifi = pywifi.PyWiFi()
    iface = iwifi.interfaces()[0]  #无线网卡
    iface.scan()
    wifis = iface.scan_results()
    for wifi in wifis:
        print(wifi.ssid)
示例#9
0
def wifi_list():
    wifi = pywifi.PyWiFi()  # 创建实例
    iface = wifi.interfaces()[0]  # 调用网卡
    while True:
        iface.scan()  # 扫描
        time.sleep(2)  # 延迟两秒
        wifi_l = iface.scan_results()  # 所有WiFi数据
        wifi = [(i.ssid, i.signal, i) for i in wifi_l]
        # 根据信号强弱排序,并去除重复名称
        wifi.sort(key=lambda x: x[1], reverse=True)
        lTemp = {}
        for i in wifi:
            if i[0] not in lTemp.keys():
                lTemp[i[0]] = i[1]
        wifis = list(lTemp.items())
        suda_wifi = []  # 连接wifi:优先连接5G的
        for i in wifis:
            if "SUDA_WIFI_5G" == i[0]:
                suda_wifi.append(i)
            if "SUDA_WIFI" == i[0]:
                suda_wifi.append(i)
        suda_wifi.sort(reverse=True)
        if suda_wifi:
            print "正在连接的网络为:{}".format(suda_wifi[0][0])
            wifi_n = suda_wifi[0][0]
            break
        else:
            print '无苏大WiFi!'
            time.sleep(10)
        time.sleep(1)

    return wifi_n
示例#10
0
def connect_wifi(name, password):
    wifi = pywifi.PyWiFi()

    iface = wifi.interfaces()[0]

    iface.disconnect()
    time.sleep(1)
    assert iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

    profile = pywifi.Profile()
    profile.ssid = name
    profile.auth = const.AUTH_ALG_OPEN
    profile.akm.append(const.AKM_TYPE_WPA2PSK)
    profile.cipher = const.CIPHER_TYPE_CCMP
    profile.key = password

    iface.remove_all_network_profiles()
    tmp_profile = iface.add_network_profile(profile)

    iface.connect(tmp_profile)
    time.sleep(4)
    if iface.status() == const.IFACE_CONNECTED:
        return True
    else:
        return False
示例#11
0
 def connect_wifi(self, ssid, password):
     self.interfice.disconnect()
     assert self.interfice.status() in [
         const.IFACE_DISCONNECTED, const.IFACE_INACTIVE
     ]
     wifi = pywifi.PyWiFi()
     interfice = wifi.interfaces()[0]
     profile = pywifi.Profile()
     profile.ssid = ssid
     profile.auth = const.AUTH_ALG_OPEN
     profile.akm.append(const.AKM_TYPE_WPA2PSK)
     profile.cipher = const.CIPHER_TYPE_CCMP
     profile.key = password
     interfice.remove_all_network_profiles()
     tmp_profile = interfice.add_network_profile(profile)
     interfice.connect(tmp_profile)
     number = 0
     while interfice.status() != const.IFACE_CONNECTED:
         time.sleep(2)
         if interfice.status() == const.IFACE_CONNECTED:
             return True
         else:
             print(number)
             number = number + 1
             if number >= 3:
                 print('connect error!')
                 break
     return False
示例#12
0
def test_profile_comparison():

    wifi = pywifi.PyWiFi()

    iface = wifi.interfaces()[0]

    profile1 = pywifi.Profile()
    profile1.ssid = 'testap'
    profile1.auth = const.AUTH_ALG_OPEN
    profile1.akm.append(const.AKM_TYPE_WPA2PSK)
    profile1.cipher = const.CIPHER_TYPE_CCMP
    profile1.key = '12345678'

    profile2 = pywifi.Profile()
    profile2.ssid = 'testap'
    profile2.auth = const.AUTH_ALG_OPEN
    profile2.akm.append(const.AKM_TYPE_WPA2PSK)
    profile2.cipher = const.CIPHER_TYPE_CCMP
    profile2.key = '12345678'

    assert profile1 == profile2

    profile3 = pywifi.Profile()
    profile3.ssid = 'testap'
    profile3.auth = const.AUTH_ALG_OPEN
    profile3.akm.append(const.AKM_TYPE_WPAPSK)
    profile3.cipher = const.CIPHER_TYPE_CCMP
    profile3.key = '12345678'

    assert profile1 == profile3
示例#13
0
def bies():
    wifi = pywifi.PyWiFi()
    ifaces = wifi.interfaces()[0]
    ifaces.scan()  # 扫描wifi
    result = ifaces.scan_results()
    for name in result:
        print(name.ssid)  # ssid wifi名称
示例#14
0
def getwifi(wifilist, wificount):
    wifi = pywifi.PyWiFi()  # 抓取网卡接口
    ifaces = wifi.interfaces()[0]  # 获取网卡
    ifaces.scan()
    time.sleep(8)
    bessis = ifaces.scan_results()
    allwifilist = []
    namelist = []
    ssidlist = []
    for data in bessis:
        if data.ssid not in namelist:  #去掉重命名的wifi名称
            namelist.append(data.ssid)
            allwifilist.append((data.ssid, data.signal))
            sorted(allwifilist, key=lambda st: st[1], reverse=True)
            time.sleep(1)
            n = 0
            if len(allwifilist) is not 0:
                for item in allwifilist:
                    if (item[0] not in ssidlist) & (item[0] not in wifilist):
                        n += 1
                        if n <= wificount:
                            ssidlist.append(item[0])
                            print(allwifilist)

    return ssidlist
示例#15
0
 def __init__(self,list1):
     
     self.STR=1
     self.NUMBER =2
     self.root =Tk()
     self.root.geometry("300x300")
     self.root.title("wifi破解")
     
     self.objevg =[]
     for i in range(self.NUMBER):
         self.objevg.append([])
         
     self.listevg=[]
     self.list1 =list1
     self.Lbox =Listbox(self.root,width="40")
     self.Lbox.grid(row =1,column=0)
     self.Lbox.insert(END,"查询中......")
     self.btn =Button(self.root,text="开始破解",command=self.XianCheng)
     self.btn.grid(row =0,column =0)
     wifi = pywifi.PyWiFi() #抓取网卡接口
 
     self.iface = wifi.interfaces()[0]#抓取第一个无限网卡
 
     self.iface.disconnect() #测试链接断开所有链接
 
     time.sleep(1) #休眠1秒
 
     #测试网卡是否属于断开状态,
     assert self.iface.status() in\
         [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
     self.root.mainloop()
     
     pass
示例#16
0
def bies():
    wifi = pywifi.PyWiFi()  #创建一个无限对象
    ifaces = wifi.interfaces()[0]  #取一个无线网卡
    ifaces.scan()  #扫描
    bessis = ifaces.scan_results()
    for i in range(len(bessis)):
        print(bessis[i].ssid, bessis[i].signal)
    def test_wifi_connect(self, pass_str):
        wifi = pywifi.PyWiFi()  # 创建一个wifi对象
        interface = wifi.interfaces()[0]  # 抓取无线网卡列表第一个无线网卡
        interface.disconnect()  # 断开无线网卡链接
        time.sleep(3)  # 断开以后缓冲3秒

        profile = pywifi.Profile()  # 配置文件
        profile.ssid = "ACFUN"  # 设置wifi名称
        profile.auth = const.AUTH_ALG_OPEN  # 需要密码链接
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  # wifi加密算法
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
        profile.key = pass_str  # 测试密码成功或者失败

        interface.remove_all_network_profiles()  # 删除其他所有配置文件
        tmp_profile = interface.add_network_profile(profile)  # 加载配置文件

        interface.connect(tmp_profile)  # 进行连接
        time.sleep(5)  # 5秒之内测试连接是否成功。
        isOK = False
        if interface.status() == const.IFACE_CONNECTED:
            isOK = True
            print("%s 链接成功,密码是:%s" % (profile.ssid, pass_str))

        else:
            print("WIFI %s 链接失败" % profile.ssid)

        interface.disconnect()  # 断开连接
        del wifi
        del interface
        return isOK
示例#18
0
def test_connect():

    wifi = pywifi.PyWiFi()

    iface = wifi.interfaces()[0]

    iface.disconnect()
    time.sleep(1)
    assert iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

    profile = pywifi.Profile()
    profile.ssid = 'testap'
    profile.auth = const.AUTH_ALG_OPEN
    profile.akm.append(const.AKM_TYPE_WPA2PSK)
    profile.cipher = const.CIPHER_TYPE_CCMP
    profile.key = '12345678'

    iface.remove_all_network_profiles()
    tmp_profile = iface.add_network_profile(profile)

    iface.connect(tmp_profile)
    time.sleep(40)
    assert iface.status() == const.IFACE_CONNECTED

    iface.disconnect()
    time.sleep(1)
    assert iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
	def __init__(self, passwordlist, istart, iend):
		threading.Thread.__init__(self)
		self.wifi = pywifi.PyWiFi()  # 开启一个无线对象
		self.iface = self.wifi.interfaces()[0]  # 抓取无线网卡列表第一个无线网卡
		self.passwordlist = passwordlist  # 密码列表
		self.istart = istart  # 开始
		self.iend = iend  # 结束
示例#20
0
def test_connect(findStr, ssidname):
    profile = pywifi.Profile()
    profile.ssid = ssidname
    profile.auth = const.AUTH_ALG_OPEN
    profile.akm.append(const.AKM_TYPE_WPA2PSK)
    profile.cipher = const.CIPHER_TYPE_CCMP
    profile.key = findStr

    # 删除所有的链接

    wifi = pywifi.PyWiFi()
    iface = wifi.interfaces()[0]
    iface.remove_all_network_profiles()
    tmp_profile = iface.add_network_profile(profile)

    iface.connect(tmp_profile)
    time.sleep(3)

    # 判断是否链接成功
    if iface.status() == const.IFACE_CONNECTED:
        isOk = True
    else:
        isOk = False
        print('密码错误:{}'.format(findStr))
    iface.disconnect()
    time.sleep(2)
    return isOk
示例#21
0
def test_status():

    wifi = pywifi.PyWiFi()

    iface = wifi.interfaces()[0]
    assert iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
示例#22
0
def test_connect_hidden():
    wifi = pywifi.PyWiFi()

    iface = wifi.interfaces()[0]

    iface.disconnect()
    time.sleep(1)
    assert iface.status() in \
           [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

    profile = pywifi.Profile()
    profile.ssid = 'hiddentestap'
    profile.auth = const.AUTH_ALG_OPEN
    profile.akm.append(const.AKM_TYPE_NONE)
    profile.hidden = True

    iface.remove_all_network_profiles()
    tmp_profile = iface.add_network_profile(profile)

    iface.connect(tmp_profile)
    time.sleep(40)
    assert iface.status() == const.IFACE_CONNECTED

    iface.disconnect()
    time.sleep(1)
    assert iface.status() in \
           [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
示例#23
0
def wificonnect(str, wifiname):
    # 窗口无线对象
    wifi = pywifi.PyWiFi()
    # 抓取第一个无线网卡
    ifaces = wifi.interfaces()[0]
    # 断开所有的wifi
    ifaces.disconnect()
    time.sleep(1)
    if ifaces.status() == const.IFACE_DISCONNECTED:
        # 创建wifi连接文件
        profile = pywifi.Profile()
        profile.ssid = wifiname
        # wifi的加密算法
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        # wifi的密码
        profile.key = str
        # 网卡的开发
        profile.auth = const.AUTH_ALG_OPEN
        # 加密单元,这里需要写点加密单元否则无法连接
        profile.cipher = const.CIPHER_TYPE_CCMP

        # 删除所有的wifi文件
        ifaces.remove_all_network_profiles()
        # 设置新的连接文件
        tep_profile = ifaces.add_network_profile(profile)
        # 连接
        ifaces.connect(tep_profile)
        time.sleep(3)

        if ifaces.status() == const.IFACE_CONNECTED:
            return True
        else:
            return False
示例#24
0
def deswifi():
    wifi = pywifi.PyWiFi()  # 创建一个wifi对象
    ifaces = wifi.interfaces()[0]  # 取第一个无限网卡
    print(ifaces.name())  # 输出无线网卡名称
    ifaces.disconnect()  # 断开网卡连接
    time.sleep(3)  # 缓冲3秒
    profile = pywifi.Profile()  # 配置文件
    for ssid in bies():
        profile.ssid = "502"  # wifi名称
        # profile.auth = const.AUTH_ASG_OPEN  # 需要密码
        # profile.akm.append(const.AKM_TYPE_WPA2SK)  # 加密类型
        profile.auth = const.AUTH_ALG_OPEN  # 需要密码
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  # 加密类型
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
        ifaces.remove_all_network_profiles()  # 删除其他配置文件
        tmp_profile = ifaces.add_network_profile(profile)  # 加载配置文件
        ifaces.connect(tmp_profile)  # 连接
        time.sleep(10)  # 尝试10秒能否成功连接
        isok = True
        if ifaces.status() == const.IFACE_CONNECTED:
            print("成功连接")
        else:
            print("失败")
        ifaces.disconnect()  # 断开连接
        time.sleep(1)
    return isok
示例#25
0
文件: wifi-1.py 项目: 1712825001/dong
def wifiConnect(pwd):
    # 抓取网卡接口
    wifi = pywifi.PyWiFi()
    # 获取第一个无线网卡
    ifaces = wifi.interfaces()[0]
    # 断开所有连接
    ifaces.disconnect()
    time.sleep(1)
    wifistatus = ifaces.status()
    if wifistatus == const.IFACE_DISCONNECTED:
        # 创建WiFi连接文件
        profile = pywifi.Profile()
        # 要连接WiFi的名称
        profile.ssid = "李"
        # 网卡的开放状态
        profile.auth = const.AUTH_ALG_OPEN
        # wifi加密算法,一般wifi加密算法为wps
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        # 加密单元
        profile.cipher = const.CIPHER_TYPE_CCMP
        # 调用密码
        profile.key = pwd
        # 删除所有连接过的wifi文件
        ifaces.remove_all_network_profiles()
        # 设定新的连接文件
        tep_profile = ifaces.add_network_profile(profile)
        ifaces.connect(tep_profile)
        # wifi连接时间
        time.sleep(3)
        if ifaces.status() == const.IFACE_CONNECTED:
            return True
        else:
            return False
    else:
        print("已有wifi连接")
示例#26
0
    def detect_wifi(self):
        global server_signal

        server_signal = {
            "edgeserver2/available/area1": 0,
            "edgeserver4/available/area1": 0,
            "edgeserver6/available/area1": 0
        }

        signal_info = {}

        wifi = pywifi.PyWiFi()
        iface = wifi.interfaces()[0]

        iface.scan()
        time.sleep(3)
        result = iface.scan_results()

        for i in range(len(result)):
            signal_info[result[i].ssid] = result[i].signal

        for key in server_signal.keys():
            server_signal[key] = signal_info[key]

        print(server_signal)
示例#27
0
def scan_wifi():
    wifi = pywifi.PyWiFi()
    iface = wifi.interfaces()[0]
    print('%s start scaning>>>>>>>' % (iface.name()))
    iface.scan()
    time.sleep(3)
    wifi_List = iface.scan_results()
    for m in wifi_List:
        print(m, "----------", m.ssid)
    # print( len(wifi_List) )
    if len(wifi_List) != 0:
        print("catched wifi list:")
        for i_wifi in wifi_List:
            print("[%d]  %s" % (wifi_List.index(i_wifi) + 1, i_wifi.ssid))
            print(
                "bssid--%s,ssid--%s,freq--%s,auth--%s,akm--%s,signal--%s,cipher--%s"
                % (i_wifi.bssid, i_wifi.ssid, i_wifi.freq, i_wifi.auth,
                   i_wifi.akm, i_wifi.signal, i_wifi.cipher))
    print("----please input the number of wifi which to crack!----")
    wifi_name = int(input()) - 1
    print("---start crack %s----" % (wifi_List[wifi_name].ssid))
    # print( "bssid--%s,ssid--%s,freq--%s,auth--%s,akm--%s,signal--%s,cipher--%s" %(wifi_List[wifi_name].bssid,wifi_List[wifi_name].ssid,wifi_List[wifi_name].freq,wifi_List[wifi_name].auth,wifi_List[wifi_name].akm,wifi_List[wifi_name].signal,wifi_List[wifi_name].cipher ) )
    profile = pywifi.Profile()
    profile.ssid = wifi_List[wifi_name].ssid
    profile.auth = const.AUTH_ALG_OPEN
    profile.akm = wifi_List[wifi_name].akm
    profile.cipher = const.CIPHER_TYPE_CCMP
    profile.key = ''
    iface.remove_all_network_profiles()
    iface.disconnect()
    return profile
示例#28
0
def connect_wifi():
    wifi = pywifi.PyWiFi()  # 创建一个wifi对象
    ifaces = wifi.interfaces()[1]  # 取第一个无限网卡
    print(ifaces.name())  # 输出无线网卡名称
    ifaces.disconnect()  # 断开网卡连接
    time.sleep(3)  # 缓冲3秒
    profile = pywifi.Profile()  # 配置文件
    profile.ssid = "TELUSWiFi0421"  # wifi名称
    profile.auth = const.AUTH_ALG_OPEN  # 需要密码
    profile.akm.append(const.AKM_TYPE_WPA2PSK)  # 加密类型
    profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
    profile.key = 'eQPm4QtXrx'  #wifi密码
    ifaces.remove_all_network_profiles()  # 删除其他配置文件
    tmp_profile = ifaces.add_network_profile(profile)  # 加载配置文件
    ifaces.connect(tmp_profile)  # 连接
    time.sleep(5)
    if ifaces.status() != const.IFACE_CONNECTED:
        profile = pywifi.Profile()  # 配置文件
        profile.ssid = "TELUS1773"  # wifi名称
        profile.auth = const.AUTH_ALG_OPEN  # 需要密码
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  # 加密类型
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
        profile.key = '9nnx6aq94j'  #wifi密码
        ifaces.remove_all_network_profiles()  # 删除其他配置文件
        tmp_profile = ifaces.add_network_profile(profile)  # 加载配置文件
        ifaces.connect(tmp_profile)  # 连接
        if ifaces.status() != const.IFACE_CONNECTED:
            connect_wifi()
        else:
            return
    else:
        return
示例#29
0
def GetWlan0Interface():
    wifi = pywifi.PyWiFi()
    interfaces = wifi.interfaces()
    for interface in interfaces:
        if "wlan0" == interface.name():
            return interface
    return
示例#30
0
def connectWifi():
    print("进入")
    wifi = pywifi.PyWiFi()  # 创建一个无线对象
    ifaces = wifi.interfaces()  # 获取pc机的无线网卡

    iface = ifaces[0]  # 取第一个无线网卡

    profiles = iface.network_profiles()  #获取pc机此前连接过的所有wifi的配置profile
    for item in profiles:
        if item.ssid == connect_wifi_name:  # 连接目标wifi
            # temp_profile=iface.add_network_profile(item)  # 设定连接文件
            iface.connect(item)  # 开始连接wifi
            time.sleep(5)  #等待3秒钟
            break  #跳出循环

    login()
    if iface.status() == const.IFACE_CONNECTED:  #判断连接状态是否为4
        print("连接已有配置成功")
        if testNetwork():  #测试是否能上外网
            print("开始上网吧~")
        else:
            print("开始准备打开浏览器")

    else:
        # getWifi(iface) #该方法以后会有妙用,不过这里先注释掉
        print("连接已有配置失败,开始尝试连接新的wifi")