简体   繁体   English

设置ip地址python

[英]set ip address python

i use wmi moudle and try to change my own computer IP Address without any success, its seems that there is not any errors in the running but the the ip address didn't changed i already checked if i have maybe multiple adapters but i have only one 我使用wmi moudle尝试更改我自己的计算机IP地址,但没有成功,看来运行中没有任何错误,但是ip地址没有更改。我已经检查了是否有多个适配器,但是我只有一

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])

output: 输出:

(-2147024891,)
(67,)

EDIT: I think its due its not running under adminstrator, how can i make it to run automatic by adminstrator? 编辑:我认为其由于未在管理员下运行,我如何使其由管理员自动运行?

答案是,如果我没有以管理员身份运行,它将忽略代码,但是当我以管理员身份运行时,它将起作用

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

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