简体   繁体   English

我尝试通过 python 上的一个脚本在 ubuntu 中连接网络 wifi

[英]I try connect a network wifi in ubuntu through one script on python

i want to connect a wifi network through python on terminal, in Ubuntu 20.04 i connect with this line:我想通过终端上的 python 连接 wifi 网络,在 Ubuntu 20.04 中,我用这条线连接:

nmcli dev wifi con "ssid" password "hereP"

i want to do this with python but i found two problems, i can run commands of linux with "import so:so.system("nmcli dev wifi con "ssid" password "hereP"")"我想用 python 来做这个,但我发现了两个问题,我可以运行 linux 的命令“import so:so.system(”nmcli dev wifi con“ssid”密码“hereP””)”

first issue: when the password is an alert appears that the password is wrong, How can I show the error by console?第一个问题:当密码提示出现密码错误时,如何通过控制台显示错误?

second issue: i want to implement a for with one array of possible passwords, i new in programming, i know that for syntax is a (for word in words) but i don't know execute in this situation.第二个问题:我想用一个可能的密码数组实现一个 for,我是编程新手,我知道 for 语法是 a(for word in words),但我不知道在这种情况下执行。

history not relevant but i tell it.历史不相关,但我告诉它。

i had a mifi (mf93d) i changed the password and not remember which is, and I am unable to connect in any other way to change the password and it is not allowed to restore to factory settings so the only way I have is to recover the password from the wifi, which I know starts with "Mifiune".我有一个mifi(mf93d)我更改了密码但不记得是哪个,我无法以任何其他方式连接来更改密码,并且不允许恢复到出厂设置,所以我唯一的方法就是恢复wifi的密码,我知道它以“Mifiune”开头。

Please help me!请帮我! I had a lot of fun trying to solve this problem on my own but I feel stuck我在尝试自己解决这个问题时玩得很开心,但我觉得卡住了

You can use subprocess module for that like this:您可以像这样使用 subprocess 模块:

import subprocess
subprocess.run(["nmcli", "dev", "wifi", "con", "ssid", "password", "hereP"])

But remember not to include space inside quotes and remember to type inside lists if there are more parameters.但请记住不要在引号内包含空格,如果有更多参数,请记住在列表中键入。

Hope it will help希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM