繁体   English   中英

Python 更改ip、su.net和网关的脚本

[英]Python script for changing ip, subnet and gateway

您好,我正在尝试编写一个脚本来更改我的 ip、su.net 掩码和网关。

脚本运行,不给出任何错误但不改变任何东西。 即使是印刷品,新的 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)

更改所有这些需要 windows 重新启动。 尝试重新启动,你会看到你的 IP 已经改变了。

name="FirstSetup"

该名称应该是分配给您要更改的接口的名称,通常类似于“Ethe.net 适配器 Ethe.net 1”或“无线 LAN 适配器本地连接 1”。 除非您的界面实际上以某种方式命名为“FirstSetup”,否则您不会更改任何内容。

运行“ipconfig /all”以查看您的接口名称并选择您要更改的地址为 IP 的接口。

暂无
暂无

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

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