当 if 语句为真时显示 elif 语句 显示语句超过 1 次
Showing the elif statement when the if statement is true showing the statements more than 1 time
我的项目有问题
只看我的代码
import subprocess
a=input("WANT SPECIFIC PASSWORD OR OF ALL if all type all if specific type wifi name")
if(a=="all"):
data=subprocess.check_output(['netsh','wlan','show','profiles']).decode('utf-8').split('\n')
wifis=[line.split(':')[1][1:-1] for line in data if"All User Profile"in line]
for wifi in wifis:
resilt=subprocess.check_output(['netsh','wlan','show','profile',wifi,'key=clear']).decode('utf-8').split('\n')
resilt=[line.split(':')[1][1:-1]for line in resilt if "Key Content" in line]
try:
print('Name',':',wifi,'Password:'+resilt[0])
except IndexError:
print('Name',':',wifi,'Password : Cannot be read!')
else:
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
wifis = [line.split(':')[1][1:-1] for line in data if "All User Profile" in line]
for wifi in wifis:
resilt = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', wifi, 'key=clear']).decode('utf-8').split(
'\n')
resilt = [line.split(':')[1][1:-1] for line in resilt if "Key Content" in line]
if (a in wifi):
# print('Name :', fg, "\n"'Password:' + resilt[0])
try:
print('Name :',a,"\n"'Password:' + resilt[0])
except IndexError:
print('Name', ':', a, 'Password zz: There is no password!')
elif (a not in wifi):
print("There is no wifi name",a,"in your system")
这里我的问题是,当我输入所有内容以获取我电脑中的所有 wifi 密码时,它工作正常,但是当我提供特定的 wifi 名称以获取其密码时,它给出 but.Just 看照片
这里显示密码,但也显示“您的系统中没有 wifi 名称 Priyanshu”,我在这里给出正确的 name.I 只是希望它只显示名称和密码没有任何其他东西和声明“没有 wifi ......”它显示了 6 次没有一次 time.I 只想要名称和密码
当我输入错误的密码时
然后它显示语句 6 次,而不仅仅是一次 Time.I 只想要一次。
我只是不知道我必须做什么。
你有一个 for 循环,在它里面,你有 if 和 elif 语句。所以它发现它会打印它,如果没有,它会打印消息,(正如你在输出的第一个屏幕截图中所看到的)。
如果没有这个wifi,还是会打印出来
我认为没有问题,脚本正常运行。
如果找到当前的 wifi 也可以跳出循环,最好不要打印“找不到 wifi...”...
代码正确,但这是您要求的定制版本
for wifi in wifis:
resilt = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', wifi, 'key=clear']).decode('utf-8').split(
'\n')
resilt = [line.split(':')[1][1:-1] for line in resilt if "Key Content" in line]
if (a in wifi):
# print('Name :', fg, "\n"'Password:' + resilt[0])
try:
print('Name :',a,"\n"'Password:' + resilt[0])
except IndexError:
print('Name', ':', a, 'Password zz: There is no password!')
break
else :
print("There is no wifi name",a,"in your system")
说明:
如果找到具有所需名称的 wifi,则执行 if 块中的代码。它还执行终止循环的 break 命令。最后一个 else 语句仅在 for 循环执行完毕后终止时才执行。因此,如果找不到所需的 wifi,它将执行。但是,如果找到所需的 wifi,则 break 命令将跳过 else 部分。
我的项目有问题 只看我的代码
import subprocess
a=input("WANT SPECIFIC PASSWORD OR OF ALL if all type all if specific type wifi name")
if(a=="all"):
data=subprocess.check_output(['netsh','wlan','show','profiles']).decode('utf-8').split('\n')
wifis=[line.split(':')[1][1:-1] for line in data if"All User Profile"in line]
for wifi in wifis:
resilt=subprocess.check_output(['netsh','wlan','show','profile',wifi,'key=clear']).decode('utf-8').split('\n')
resilt=[line.split(':')[1][1:-1]for line in resilt if "Key Content" in line]
try:
print('Name',':',wifi,'Password:'+resilt[0])
except IndexError:
print('Name',':',wifi,'Password : Cannot be read!')
else:
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
wifis = [line.split(':')[1][1:-1] for line in data if "All User Profile" in line]
for wifi in wifis:
resilt = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', wifi, 'key=clear']).decode('utf-8').split(
'\n')
resilt = [line.split(':')[1][1:-1] for line in resilt if "Key Content" in line]
if (a in wifi):
# print('Name :', fg, "\n"'Password:' + resilt[0])
try:
print('Name :',a,"\n"'Password:' + resilt[0])
except IndexError:
print('Name', ':', a, 'Password zz: There is no password!')
elif (a not in wifi):
print("There is no wifi name",a,"in your system")
这里我的问题是,当我输入所有内容以获取我电脑中的所有 wifi 密码时,它工作正常,但是当我提供特定的 wifi 名称以获取其密码时,它给出 but.Just 看照片
这里显示密码,但也显示“您的系统中没有 wifi 名称 Priyanshu”,我在这里给出正确的 name.I 只是希望它只显示名称和密码没有任何其他东西和声明“没有 wifi ......”它显示了 6 次没有一次 time.I 只想要名称和密码
当我输入错误的密码时
然后它显示语句 6 次,而不仅仅是一次 Time.I 只想要一次。
我只是不知道我必须做什么。
你有一个 for 循环,在它里面,你有 if 和 elif 语句。所以它发现它会打印它,如果没有,它会打印消息,(正如你在输出的第一个屏幕截图中所看到的)。
如果没有这个wifi,还是会打印出来
我认为没有问题,脚本正常运行。
如果找到当前的 wifi 也可以跳出循环,最好不要打印“找不到 wifi...”...
代码正确,但这是您要求的定制版本
for wifi in wifis:
resilt = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', wifi, 'key=clear']).decode('utf-8').split(
'\n')
resilt = [line.split(':')[1][1:-1] for line in resilt if "Key Content" in line]
if (a in wifi):
# print('Name :', fg, "\n"'Password:' + resilt[0])
try:
print('Name :',a,"\n"'Password:' + resilt[0])
except IndexError:
print('Name', ':', a, 'Password zz: There is no password!')
break
else :
print("There is no wifi name",a,"in your system")
说明: 如果找到具有所需名称的 wifi,则执行 if 块中的代码。它还执行终止循环的 break 命令。最后一个 else 语句仅在 for 循环执行完毕后终止时才执行。因此,如果找不到所需的 wifi,它将执行。但是,如果找到所需的 wifi,则 break 命令将跳过 else 部分。