Ejemplo n.º 1
0
def test_scan():
    wifi = PyWiFi()
    iface = wifi.interfaces()[0]
    iface.scan()
    bsses = iface.scan_results()
    for bss in bsses:
        print("WIFI名称: %s" % bss.ssid)
Ejemplo n.º 2
0
def test_interfaces():
    wifi = PyWiFi()
    ifaces = wifi.interfaces()[0]
    if ifaces.status() in [const.IFACE_CONNECTED, const.IFACE_CONNECTING]:
        print('无线网卡 %s 已连接!' % ifaces.name())
    else:
        print('无线网卡 %s 未连接!' % ifaces.name())
def Get_WiFi_Interface_Name():

    #creating an object of PyWiFi class
    wifiobj = PyWiFi()

    wifi_interface_name = -1
    wifi_interfaces = []
    #getting the list of all the wifi interfaces connected to system
    try:
        wifi_interfaces = wifiobj.interfaces()

    except (FileNotFoundError, PermissionError, Exception) as err:

        ErrorName = type(err).__name__
        ErrorMsg = str(err)

        if ErrorName == "FileNotFoundError":  #error when we aren't connected to WiFi
            return CONNECTION_ERROR
        elif ErrorName == "PermissionError":  #error when Permissions aren't given
            return PERMISSION_ERROR

    else:
        for item in wifi_interfaces:
            wifi_interface_name = item.name()

            #check the wifi interface name start with "wl"
            if wifi_interface_name[0:2] == "wl":
                break

        return wifi_interface_name
Ejemplo n.º 4
0
def pass2():
    with open("D:/2.txt", "r") as f:
        for wifi_password in f:
            wifi = PyWiFi()
            iface = wifi.interfaces()[0]
            iface.disconnect()
            time.sleep(1)
            info = Profile()
            info.ssid = 'ChinaNet-FMNS'
            info.auth = const.AUTH_ALG_OPEN
            info.akm.append(const.AKM_TYPE_WPA2PSK)
            info.cipher = const.CIPHER_TYPE_CCMP
            info.key = wifi_password
            iface.remove_all_network_profiles()
            tmp = iface.add_network_profile(info)
            iface.connect(tmp)
            time.sleep(3)

            if iface.status() == const.IFACE_CONNECTED:
                print('成功')
                print(wifi_password)

                break

            else:
                print('失败')
                print(wifi_password)
Ejemplo n.º 5
0
def connect(wifi_name, wifi_password, auth_type):
	'''Connect WiFi'''
	wifi = PyWiFi()
	iface = wifi.interfaces()[0]
	iface.disconnect()
	time.sleep(1)
	profile_info = Profile()
	profile_info.ssid = wifi_name
	profile_info.auth = const.AUTH_ALG_OPEN
	if auth_type == "OPEN":
		profile_info.akm.append(const.AKM_TYPE_NONE)
		profile_info.cipher = const.CIPHER_TYPE_NONE
	else:
		profile_info.akm.append(const.AKM_TYPE_WPA2PSK)
		profile_info.cipher = const.CIPHER_TYPE_CCMP
	profile_info.key = wifi_password
	iface.remove_all_network_profiles()
	tmp_profile = iface.add_network_profile(profile_info)
	iface.connect(tmp_profile)
	time.sleep(1)
	if iface.status() == const.IFACE_CONNECTED:
		print("WiFi: %s 连接成功" % wifi_name)
		return True
	else:
		print("WiFi: %s 连接失败" % wifi_name)
		return False
Ejemplo n.º 6
0
def test_disconnect():
    wifi = PyWiFi()
    ifaces = wifi.interfaces()[0]
    ifaces.disconnect()
    if ifaces.status() in [const.IFACE_DISCONNECTED,const.IFACE_INACTIVE]:
        print("无线网卡 %s 未连接!" % ifaces.name())
    else:
        print("无线网卡 %s 未连接!" % ifaces.name())
Ejemplo n.º 7
0
def check_state():
    wifi = PyWiFi()
    iface = wifi.interfaces()[0]
    print(iface.status())
    if iface.status() == 4:
        print('connected')
    else:
        print('broken')
Ejemplo n.º 8
0
    def __init__(self):
        self.wifi = PyWiFi()
        self.iface = self.wifi.interfaces()[0]

        self.akm = {
            'None': const.AKM_TYPE_NONE,
            'WPA': const.AKM_TYPE_WPAPSK,
            'WPA2': const.AKM_TYPE_WPA2PSK,
        }
Ejemplo n.º 9
0
def disconnect():
	'''Disconnect wireless network card'''
	wifi = PyWiFi()
	ifaces = wifi.interfaces()[0]
	ifaces.disconnect()
	if ifaces.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]:
		print("无线网卡 %s 未连接!" % ifaces.name())
	else:
		print("无线网卡 %s 已连接!" % ifaces.name())
Ejemplo n.º 10
0
Archivo: main.py Proyecto: hensir/LANTT
 def on_StB5_clicked(self):
     wifi = PyWiFi()
     iface = wifi.interfaces()[0]
     self.ui.StE.append("网卡接口为\n" + iface.name())
     profile = Profile()
     profile.ssid = "LANTT"
     profile.auth = const.AUTH_ALG_OPEN
     profile.akm.append(const.AKM_TYPE_WPA2PSK)
     profile.cipher = const.CIPHER_TYPE_CCMP
     profile.key = "5607893124"
     tep_profile = iface.add_network_profile(profile)
     iface.connect(tep_profile)
Ejemplo n.º 11
0
def check_state():
    wifi = PyWiFi()

    # 无线网卡
    faces = wifi.interfaces()
    if not faces:
        print("此电脑未安装无线网卡.")
        return

    # 判断第一个无线网卡的连接状态
    print(faces[0].status())
    if faces[0].status() == 4:
        print("电脑已连接WIFI.")
    else:
        print("电脑未连接WIFI.")
Ejemplo n.º 12
0
def get_wireless():
    wifi = PyWiFi()
    faces = wifi.interfaces()
    if not faces:
        print("此电脑未安装无线网卡.")
        return

    # face[0].scan() 扫描附近的无线信号
    wireless = faces[0].scan_results()

    print(wireless)

    for data in wireless:
        print("-" * 20)
        print(data.ssid)  # 无线信号名称
        print(AKMS[data.akm[0]])  # 加密方式
        print("-" * 20)
Ejemplo n.º 13
0
def test_connect(wifi_name,wifi_password):
    wifi = PyWiFi()
    iface = wifi.interfaces()[0]
    test_disconnect()
    time.sleep(3)
    profile_info = Profile()
    profile_info.ssid = wifi_name
    profile_info.auth = const.AUTH_ALG_OPEN
    profile_info.akm.append(const.AKM_TYPE_NONE)
    profile_info.cipher = const.CIPHER_TYPE_CCMP
    iface.remove_all_network_profiles()
    tmp_profile = iface.add_network_profile(profile_info)
    iface.connect(tmp_profile)
    time.sleep(5)
    if iface.status() == const.IFACE_CONNECTED:
        print("wifi: %s 连接成功"% wifi_name)
    else:
        print("wifi: %s 连接失败" % wifi_name)
Ejemplo n.º 14
0
def test_scan():
    wifi = PyWiFi()  # 创建一个无线对象
    iface = wifi.interfaces()[0]  # 取一个无限网卡
    iface.scan()  # 扫描s
    # (必不可少)这个sleep时间必须有,不知道为啥。
    time.sleep(0.5)
    wifi_information = {
        'ABCD': [-200, 123456789],
        'hello_world': [-200, 850898840]
    }
    result = iface.scan_results()
    for i in range(len(result)):
        if result[i].ssid in wifi_information.keys():
            wifi_information[result[i].ssid] = [
                result[i].signal, wifi_information[result[i].ssid][1]
            ]
    # time.sleep(1)
    return wifi_information
class Wifi:
    wifi = PyWiFi()

    def connect(self):
        profile = Profile()
        profile.ssid = 'BNUZ-Student'
        self.wifi.interfaces()[0].connect(profile)

    def disconnect(self):
        self.wifi.interfaces()[0].disconnect()
Ejemplo n.º 16
0
def main():
    # 扫描时长
    scantimes = 3
    # 单个密码测试延迟
    testtimes = 15
    output = sys.stdout
    # 结果文件保存路径
    files = "TestRes.txt"
    # 字典列表 super_keys
    file_path = os.path.abspath('../../../test.txt')
    print file_path
    # 密码编号
    pwd_num = 0
    with open(file_path, 'r') as f:
        for key in f:
            if not key:
                break
            pwd_num = pwd_num + 1
    # keys = open(file_path, "r").readlines()
    # print"|KEYS %s" % (len(keys))
    # 实例化一个pywifi对象
    wifi = PyWiFi()
    # 选择定一个网卡并赋值于iface
    iface = wifi.interfaces()[0]
    # 通过iface进行一个时长为scantimes的扫描并获取附近的热点基础配置
    scanres = scans(iface, scantimes)
    # 统计附近被发现的热点数量
    nums = len(scanres)
    print "|SCAN GET {0}".format(nums)

    print "%s\n%-*s|%-*s|%-*s|%-*s|%-*s|%-*s%*s\n%s" % (
        "-" * 70, 6, "WIFIID", 18, "SSID OR BSSID", 2, "N", 4, "time", 7,
        "signal", 10, "KEYNUM", 10, "KEY", "=" * 70)
    # 将每一个热点信息逐一进行测试
    for i, x in enumerate(scanres):
        # 测试完毕后,成功的结果讲存储到files中
        res = test(nums - i, iface, x, pwd_num, key, output, testtimes)
        # res = test(nums - i, iface, x, key, output, testtimes)
        print res
        if res:
            open(files, "a").write(res)
Ejemplo n.º 17
0
def get_wifi_interface():
    wifi = PyWiFi()
    if len(wifi.interfaces()) <= 0:
        print u'未找到无线网卡接口!'
        exit()
    if len(wifi.interfaces()) == 1:
        print u'无线网卡接口: %s' % (wifi.interfaces()[0].name())
        return wifi.interfaces()[0]
    else:
        print '%-4s   %s' % (u'序号', u'网卡接口名称')
        for i, w in enumerate(wifi.interfaces()):
            print '%-4s   %s' % (i, w.name())
        while True:
            iface_no = raw_input('请选择网卡接口序号:'.decode('utf-8').encode('gbk'))
            no = int(iface_no)
            if no >= 0 and no < len(wifi.interfaces()):
                return wifi.interfaces()[no]
Ejemplo n.º 18
0
def main():

    try:  #捕获异常处理,如果执行脚本不是root,就抛出错误
        if os.getuid() != 0:
            print("[-] Run me as root")
            exit(1)
    except Exception as msg:
        print(msg)
    wifi = PyWiFi()  #创建并且选择一张网卡
    iface = wifi.interfaces()[0]
    print("当前已选择网卡: %s" % iface.name())
    print('工具启动,正在扫描可用WIFI……')
    wifi_list = scan_ap(iface)  #输出一个扫描结果wifi表
    print("扫描完成!")
    while (1):
        print('--------------------------')
        print('请选择需要的服务:')
        print('1.显示可用WIFI列表')
        print('2.再次扫描')
        print('3.选择连入WIFI')
        print('4.查看当前网卡状态')
        print('5.断开当前网卡连接')
        print('6.退出程序')
        print('--------------------------')
        choice = input()
        if (choice == '1'):
            show_wifi_list(wifi_list)
        elif (choice == '2'):
            '''再次扫描,得到结果'''

            print('正在扫描……')
            wifi_list = scan_ap(iface)
            print("扫描完成!")
        elif (choice == '3'):
            connect_ap(iface, wifi_list)
        elif (choice == '4'):
            interfaces_status(iface)
        elif (choice == '5'):
            interface_disconnect(iface)
        elif (choice == '6'):
            exit(0)
Ejemplo n.º 19
0
def get_wifi_interface():
    wifi = PyWiFi()
    if len(wifi.interfaces()) <= 0:
        sys.exit('No wifi inteface found!')
    print("=" * 73)
    if len(wifi.interfaces()) == 1:
        print(O + 'Wifi interface found:' + C + wifi.interfaces()[0].name() +
              W)
        return wifi.interfaces()[0]
    else:
        print('%-4s   %s' % ('No', 'interface name'))
        for i, w in enumerate(wifi.interfaces()):
            print('%-4s   %s' % (i, w.name()))
        while True:
            iface_no = input('Please choose interface No:')
            no = int(iface_no)
            if no >= 0 and no < len(wifi.interfaces()):
                return wifi.interfaces()[no]
Ejemplo n.º 20
0
def test1(wifi_name, wifi_password):
    wifi = PyWiFi()
    iface = wifi.interfaces()[0]
    iface.disconnect()
    time.sleep(1)
    info = Profile()
    info.ssid = wifi_name
    info.auth = const.AUTH_ALG_OPEN
    info.akm.append(const.AKM_TYPE_WPA2PSK)
    info.cipher = const.CIPHER_TYPE_CCMP
    info.key = wifi_password
    iface.remove_all_network_profiles()
    tmp = iface.add_network_profile(info)
    iface.connect(tmp)
    time.sleep(3)

    if iface.status() == const.IFACE_CONNECTED:
        print('成功')
        print(wifi_password)

    else:
        print('失败')
def connect_wifi(ssid, password):
    # function to connect to Wi-Fi with Password

    wifi = PyWiFi()
    iface = wifi.interfaces()[0]
    iface.disconnect()  # disconnects from the current Wi-Fi if any
    time.sleep(2)

    profile = Profile()  # adding new Profile for given Wi-Fi
    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

    print("\nConnecting to WiFi....")
    iface.connect(iface.add_network_profile(profile))
    time.sleep(5)

    if iface.status() == const.IFACE_CONNECTED:
        print("\t>> Connected Successfully!")
    else:
        print("\t>> Failed to Connect!")
Ejemplo n.º 22
0
    def run(self):
        try:
            wifi = PyWiFi()  # 创建一个wifi对象
            iface = wifi.interfaces()[0]  # 取第一个无限网卡

            iface.disconnect()  # 断开网卡连接
            profile = Profile()  # 配置文件
            profile.ssid = "Shu(ForAll)"  # wifi名称

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

            iface.connect(tmp_profile)  # 连接
            sleep(1)  # 不延时,wifi反应不过来

            s0 = "Shu(ForAll) 连接成功\n"
            shu = shuConnect(self.user, self.passwd, chose=2)
            s = s0 + shu.start_connect()

        except:
            s = 'macError'

        self.signalCon.emit(s)
Ejemplo n.º 23
0
def connect_wifi(wifi_name, wifi_password):
    wifi = PyWiFi()  # 创建一个无限对象
    ifaces = wifi.interfaces()[0]  # 取一个无限网卡
    # print(ifaces.name())  # 输出无线网卡名称
    ifaces.disconnect()  # 断开网卡连接
    # time.sleep(1)  # 缓冲3秒
    profile_info = Profile()  # 配置文件
    profile_info.ssid = wifi_name  # wifi名称
    profile_info.auth = const.AUTH_ALG_OPEN  # 需要密码
    profile_info.akm.append(const.AKM_TYPE_WPA2PSK)  # 加密类型
    profile_info.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
    profile_info.key = wifi_password
    ifaces.remove_all_network_profiles()  # 删除其他配置文件
    tmp_profile = ifaces.add_network_profile(profile_info)  # 加载配置文件
    ifaces.connect(tmp_profile)  # 连接
    time.sleep(2)  # (必不可少)尝试2秒能否成功连接
    isok = True
    if ifaces.status() == const.IFACE_CONNECTED:
        print("成功切换连接为wifi: %s" % wifi_name)

    else:
        print("wifi: %s 连接失败" % wifi_name)
    # time.sleep(2)
    return isok
Ejemplo n.º 24
0
 def LogMessage(self):#注册一个消息 
     log_strings = ''
     if not self.network_status():
         IFACE = PyWiFi().interfaces()[0]  # 获取第一个无线网卡
         time.sleep(1)
         if not self.interfaces_status(IFACE):
             CONNECTED = self.wifi_connect(IFACE)
             if CONNECTED:
                 log_strings = '连接成功,连接时间为'+time.asctime(
                     time.localtime(time.time()))+'\n'
     else:
         log_strings = '网络正常' + \
             time.asctime(time.localtime(time.time())) + \
             '。每隔 %s 分钟检测一次\n' % self.TIME_INTERVAL
     # self.logs(log_strings)
     self.log.AppendText(log_strings)
Ejemplo n.º 25
0
import sys
import os
import os.path
import platform
import re
import time

import pywifi
from pywifi import PyWiFi
from pywifi import const
from pywifi import Profile

try:
    # wlan
    wifi = PyWiFi()
    ifaces = wifi.interfaces()[0]

    ifaces.scan()  #check the card
    results = ifaces.scan_results()

    wifi = pywifi.PyWiFi()
    iface = wifi.interfaces()[0]
except:
    print("[-] Error system")

type = False


def main(ssid, password):

    profile = Profile()
Ejemplo n.º 26
0
 def __init__(self):
     self.wifi = PyWiFi()  # 创建一个无线对象
     self.iface = self.wifi.interfaces()[0]  # 获取当前机器第一个无线网卡
Ejemplo n.º 27
0
    2412: '1',
    2417: '2',
    2422: '3',
    2427: '4',
    2432: '5',
    2437: '6',
    2442: '7',
    2447: '8',
    2452: '9',
    2457: '10',
    2462: '11',
    2467: '12',
    2472: '13'
}

iface_list = PyWiFi().interfaces()
items = sorted([iface.name() for iface in iface_list])


class Mywindow(QtWidgets.QWidget, Ui_MainWindow):
    def __init__(self):

        super(Mywindow, self).__init__()
        self.setupUi(self)
        self.scan_list = list()
        self.ScanButton.clicked.connect(self.scan_button_click)
        self.LinkButton.clicked.connect(self.link_button_click)
        self.DetectButton.clicked.connect(self.detect_button_click)
        self.ClearButton.clicked.connect(self.clear_button_click)

        self.exit_action.setShortcut('Ctrl+Q')
Ejemplo n.º 28
0
path_to_file = r"C:\Users\Sajal\Desktop\password.txt"

#######

# Setting the color combinations
RED = "\033[1;31m"
BLUE = "\033[1;34m"
CYAN = "\033[1;36m"
GREEN = "\033[0;32m"
RESET = "\033[0;0m"
BOLD = "\033[;1m"
REVERSE = "\033[;7m"

try:
    # Interface information
    wifi = PyWiFi()
    ifaces = wifi.interfaces()[0]  # for wifi we use index - 0

    ifaces.scan()  #check the card
    results = ifaces.scan_results(
    )  #Obtain the results of the previous triggerred scan. A Profile list will be returned.

    wifi = pywifi.PyWiFi(
    )  # A Profile is the settings of the AP we want to connect to
    iface = wifi.interfaces()[0]

except:
    print("[-] Error system")

type = False
Ejemplo n.º 29
0
 def iface_choose(face_name):
     iface_list = PyWiFi().interfaces()
     for interface in iface_list:
         if interface.name() == face_name:
             return interface
Ejemplo n.º 30
0
class WiFi(object):
    # 创建对象自动初始化,类似Java的构造函数
    def __init__(self):
        self.wifi = PyWiFi()  # 创建一个无线对象
        self.iface = self.wifi.interfaces()[0]  # 获取当前机器第一个无线网卡

    # 查看wifi的连接状态
    def wifi_connect_status(self):
        """
        判断本机是否有无线网卡,以及连接状态
        :return:已连接或存在网卡返回1,否则返回0
        """
        ret_list = []
        # 判断是否连接成功
        if self.iface.status() in \
                [const.IFACE_CONNECTED, const.IFACE_CONNECTING, const.IFACE_INACTIVE]:
            return self.iface.name()  # 连接成功显示连接设备
        else:
            return "not connected!"  # 连接失败返回失败信息

    """
    扫描附近wifi
        乱码问题:
        把wifi_info.ssid重新编码为gb18030
        wifi_info.ssid.encode('raw_unicode_escape','strict').decode('gb18030')
        我也不清楚他为什么不全用unicode
        ssid出来应该是unicode  但是  你往profile里面写的时候  必须是gb18030
        所以这么一个操作
        你会发现gb18030在控制台和py的某些控件上输出是乱码  是因为 控制台是utf-8
        想在这上面输出中文的话你得encode('raw_unicode_escape','strict').decode()
    """

    def scan_wifi(self, scantime=3):
        """
        :param scantime:    指定扫描时间,默认扫描时间为5秒
        :return:            返回的是一个network dictionary,key=bssid,value=ssid
        """
        self.iface.scan()  # 扫描附近wifi
        time.sleep(scantime)
        basewifi = self.iface.scan_results()
        # print("has end step2")
        dict = {}
        for i in basewifi:
            dict[i.bssid] = \
                i.ssid.encode(encoding='raw_unicode_escape', errors='strict').decode()
        # print("has end step3")
        return dict

    def get_wifi_pass(self, wifi_ssid):
        tmp = wifi_ssid
        # tmp = hashlib.md5(tmp.encode('latin1')).hexdigest()

        for i in range(3):
            tmp = tmp + '\n'
            md5_obj = hashlib.md5()  # need to every time new object
            md5_obj.update(tmp.encode('utf-8'))
            tmp = md5_obj.hexdigest()
        wifi_pass = tmp[0:7]
        root_pass = tmp[26:32]
        print(tmp,wifi_pass,root_pass)
        return wifi_pass, root_pass

    # 链接到指定wifi
    def connect_wifi(self, wifi_ssid, password):
        profile = Profile()  # 配置文件
        profile.ssid = wifi_ssid  # wifi名称
        profile.auth = const.AUTH_ALG_OPEN  # 需要密码
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  # 加密类型
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
        profile.key = password  # wifi密码

        self.iface.remove_all_network_profiles()  # 删除其他配置
        tmp_profile = self.iface.add_network_profile(profile)  # 加载配置

        self.iface.connect(tmp_profile)  # link start
        time.sleep(10)  # 尝试10s是否成功
        isok = True
        if self.iface.status() == const.IFACE_CONNECTED:
            return isok  # 连接成功
        else:
            isok = False  # 连接失败设置isok = False
        self.iface.disconnect()  # 避免超时后连接成功手动断开一下,因为在一定时间内连接失败用户会继续重试连接
        time.sleep(1)
        return isok

    def Get_Param(self):
        yamlPath = "config.xml"
        f = open(yamlPath, 'r', encoding='utf-8')