-2

The line wifi_profile["ssid"] = name is not letting the code run. It says

IndentationError: expected an indented block.

Make the line correct so that It can pass.

import subprocess

import re

command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()

profile_names = (re.findall("All User Profile       : (.*)\r", command_output))

wifi_list = list()

if len(profile_names) != 0:
    for name in profile_names:
        wifi_profile = dict()

        profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode()

        if re.search("Security key           : Absent", profile_info):
            continue
        else:
        
        wifi_profile["ssid"] = name
        
        profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode()
        

        password = re.search("Key Content            : (.*)\r", profile_info_pass)

        if password == None:
            wifi_profile["password"] = None
        else
            wifi_profile["password"] = password[1]
        wifi_list.append(wifi_profile)

for x in range(len(wifi_list)):
    print(wifi_list[x])
Hassan Ali
  • 53
  • 5

1 Answers1

1
import subprocess
import re

command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()

profile_names = (re.findall("All User Profile       : (.*)\r", command_output))

wifi_list = list()

if len(profile_names) != 0:
    for name in profile_names:
        wifi_profile = dict()

        profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode()
        if re.search("Security key           : Absent", profile_info):
            continue
        else:
            wifi_profile["ssid"] = name
        
        profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode()
        password = re.search("Key Content            : (.*)\r", profile_info_pass)

        if password == None:
            wifi_profile["password"] = None
        else: # <----- missing colon
            wifi_profile["password"] = password[1] # <----- this line was not properly indented

        wifi_list.append(wifi_profile)

for x in range(len(wifi_list)):
    print(wifi_list[x])
Robin Sage
  • 969
  • 1
  • 8
  • 24
  • command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode() AttributeError: 'module' object has no attribute 'run' – Hassan Ali Jul 04 '21 at 21:29