原理
- “netsh wlan show profiles”命令获取配置信息
- “netsh wlan show profiles name="xxx" key=clear”查看对应的密码
代码实现
python
import subprocess
# Run the PowerShell command to get the list of all Wi-Fi profiles
command = 'netsh wlan show profiles'
profiles = subprocess.check_output(['powershell', '-Command', command]).decode('utf-8')
# Loop through all profiles and get the password for each one
for profile in profiles.split('\n'):
if 'All User Profile' in profile:
ssid = profile.split(':')[1].strip()
command = f'netsh wlan show profile name="{ssid}" key=clear'
profile_info = subprocess.check_output(['powershell', '-Command', command]).decode('utf-8')
if 'Key Content' in profile_info:
password = profile_info.split('Key Content')[1].split(':')[1].strip()
print(f'SSID: {ssid}')
print(f'Password: {password}\n')