本文实例讲述了python实现自动更换ip的方法。分享给大家供大家参考。具体实现方法如下:
#!/usr/bin/env python
#-*- encoding:gb2312 -*-
# Filename: IP.py
import sitecustomize
import _winreg
import ConfigParser
from ctypes import *
print '正在进行网络适配器检测,请稍候…'
netCfgInstanceID = None
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
r'SystemCurrentControlSetControlClass{4d36e972-e325-11ce-bfc1-08002be10318}')
keyInfo = _winreg.QueryInfoKey(hkey)
# 寻找网卡对应的适配器名称 netCfgInstanceID
for index in range(keyInfo[0]):
hSubKeyName = _winreg.EnumKey(hkey, index)
hSubKey = _winreg.OpenKey(hkey, hSubKeyName)
try:
hNdiInfKey = _winreg.OpenKey(hSubKey, r'NdiInterfaces')
lowerRange = _winreg.QueryValueEx(hNdiInfKey, 'LowerRange')
# 检查是否是以太网