Home > Enterprise >  python does not run for loop
python does not run for loop

Time:07-01

I am working on a project which will extract all the ssids and passwords from a windows system (Note:I am not using this script for malicious pourposes.I just want to apply my subprocess module skills) But in this program,The for loop I wrote is not executed by python can anyone please help me with this? 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))

CodePudding user response:

You are using f.read() several times and print its contents. Use with open to open and close it safely.

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')
  • Related