【发布时间】:2023-01-04 22:59:24
【问题描述】:
您好我正在尝试编写一个脚本来更改我的 ip、子网掩码和网关。
脚本运行,不给出任何错误但不改变任何东西。连打印,新的ip还是和现在的一样。
我究竟做错了什么?
# importing os module
import os
import ipaddress
import socket
# Get the current working
# directory (CWD)
cwd = os.getcwd()
# Print the current working
# directory (CWD)
print("Current working directory:", cwd)
# Print current IP
hn = socket.gethostname()
ipa = socket.gethostbyname(hn)
print("Current IP: ",ipa)
os.system('netsh interface ip set address name="FirstSetup" static 192.168.0.20 255.255.255.0 192.168.0.1')
print("IP ADRESS CHANGED!")
# Print newIP
hn = socket.gethostname()
ipa = socket.gethostbyname(hn)
print("New IP: ",ipa)
【问题讨论】:
标签: python networking wmi python-ipaddress