代码之家  ›  专栏  ›  技术社区  ›  sudam edirisinghe

python不为循环运行

  •  1
  • sudam edirisinghe  · 技术社区  · 2 年前

    我正在从事一个项目,该项目将从windows系统中提取所有SSID和密码 (注意:我没有将此脚本用于恶意pourpoes。我只是想应用我的子流程模块技能) 但是在这个程序中,我编写的for循环不是由python执行的,有人能帮我吗?tnx。

    import subprocess , sys , re
    a = subprocess.check_output(['netsh' ,  'wlan' ,  'show' ,  'profiles'])
    a = a.decode('utf-8')
    a = a.replace('    All User Profile     :' , '')
    a = a.replace('User profiles' , '')
    a = a.replace('<None>' , '')
    a = a.replace( 'Profiles on interface Wi-Fi:', '')
    a = a.replace(':' , '')
    a = a.replace('Group policy profiles (read only)' , '')
    a = a.replace('---------------------------------' , '')
    a = a.replace('-------------' , '')
    print(a)
    a = a.replace('  ' , '')
    f = open('ssids.txt' , 'w')
    f.write(a)
    f.close()
    f = open('ssids.txt' , 'r')
    d = f.read()
    l1 = []
    print(str(f.read()))
    for line in f.read():
        l = subprocess.run('netsh wlan show profiles "' + f.readline(line) + '"' , capture_output = True , text = True)
        print(l)
    f.close()
    print('follwed')
    print(str(l1))
    
    1 回复  |  直到 2 年前
        1
  •  0
  •   AboAmmar    2 年前

    您正在使用 f.read() 多次并打印其内容。使用 with open 安全打开和关闭。

    import subprocess
    a = subprocess.check_output(['netsh' ,  'wlan' ,  'show' ,  'profiles'])
    a = a.decode('utf-8')
    a = a.replace('    All User Profile     :' , '')
    a = a.replace('User profiles' , '')
    a = a.replace('<None>' , '')
    a = a.replace( 'Profiles on interface Wi-Fi:', '')
    a = a.replace(':' , '')
    a = a.replace('Group policy profiles (read only)' , '')
    a = a.replace('---------------------------------' , '')
    a = a.replace('-------------' , '')
    print(a)
    a = a.replace('  ' , '')
    
    with open('ssids.txt' , 'w') as f:
        f.write(a)
    
    with open('ssids.txt' , 'r') as f:
        for line in f:
            l = subprocess.run('netsh wlan show profiles "' + line + '"' , capture_output = True , text = True)
            print(l)
    print('follwed')