您的当前位置:首页正文

python的ip地址_设置ip地址python

2024-11-04 来源:个人技术集锦

我已经检查过是否有多个适配器,但我只有一个import wmi

# Obtain network adaptors configurations

nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)

# First network adaptor

try:

nic = nic_configs[0]

except Exception as e:

raise Exception("חבר קודם את המחשב למתג!")

# IP address, subnetmask and gateway values should be unicode objects

ip = u'192.168.43.99'

subnetmask = u'255.255.0.0'

gateway = u'15.0.0.254'

# Set IP address, subnetmask and default gateway

# Note: EnableStatic() and SetGateways() methods require *lists* of values to be passed

print nic.EnableStatic(IPAddress=[ip],SubnetMask=[subnetmask])

print nic.SetGateways(DefaultIPGateway=[gateway])

输出:

^{pr2}$

编辑:我想它应该不在管理员下运行,我怎样才能让它自动运行?在

显示全文