|
发表于 2024-5-29 21:19:18
|
显示全部楼层
江西省南昌市
import os
def set_ipv4_address(interface, ip_address, subnet_mask, gateway):
# 设置IP地址和子网掩码
set_ip_command = f'netsh interface ip set address name="{interface}" static {ip_address} {subnet_mask} {gateway} 1'
os.system(set_ip_command)
# 设置默认网关
set_gateway_command = f'netsh interface ip set address name="{interface}" gateway={gateway} gwmetric=1'
os.system(set_gateway_command)
# 替换为你的网卡名称、IP地址、子网掩码和默认网关
network_interface = "Ethernet"
new_ip_address = "192.168.1.100"
subnet_mask = "255.255.255.0"
default_gateway = "192.168.1.1"
set_ipv4_address(network_interface, new_ip_address, subnet_mask, default_gateway)
|
|