我想连续更改机器的IP地址,因此经过大量搜索,我得到了这个有用的链接https://github.com/jotyGill/openpyn-nordvpn。我已经按照该URL执行了步骤,并尝试在终端窗口(Mac)中执行该步骤,并且它成功更改了IP。
但是问题在于,需要再次手动运行脚本来更改IP,因此请考虑使其自动化。
所以我想做的是,
1. Open an terminal window in mac using Python and execute the following commands,
Enter this command :
sudo openpyn --init
it will prompt to enter password and i have to enter password manually,Is there a way where the program can do this password input automatically using subprocess or any other methods in Python?
After the user name and password is entered ,Need to enter the below command.
openpyn US --area “area”
This will change the IP and need to do the same again.While doing the same either we need to do it from the start or pass CTRL+C to end the current execution and pass
" openpyn US --area “area” "this command again.
我正在尝试从python程序在终端窗口中执行一些语句。
这些都是我做过的事情,没有运气。有人可以指导我如何做吗?
import subprocess
import os
pid = os.fork()
os.system("""osascript -e 'tell application "Terminal" to do script "sudo openpyn --init;openpyn US --area “area”;os.kill(pid, signal.SIGINT)"'""")
subprocess.call(["sudo openpyn --init"], shell=True)
os.system("sudo openpyn --init")