Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python does not run for loop

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))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading