python 自动换ip_python实现自动更换ip的方法
本文实例讲述了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')
# 检查是否是以太网
if lowerRange[0] == 'ethernet':
driverDesc = _winreg.QueryValueEx(hSubKey, 'DriverDesc')[0]print '检测到网络适配器名:', driverDesc
netCfgInstanceID = _winreg.QueryValueEx(hSubKey, 'NetCfgInstanceID')[0]print '检测到网络适配器ID:', netCfgInstanceID
if netCfgInstanceID == None:
print '没有找到网络适配器,程序退出'
exit()
break
_winreg.CloseKey(hNdiInfKey)
except WindowsError:
print r'Message: No NdiInterfaces Key'
# 循环结束,目前只提供修改一个网卡IP的功能
_winreg.CloseKey(hSubKey)
_winreg.CloseKey(hkey)
# 通过修改注册表设置IP
strKeyName = 'SystemCurrentControlSetServicesTcpipParametersInterfaces' + netCfgInstanceID
print '网络适配器的注册表地址是:n', strKeyName
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
strKeyName,
0,
_winreg.KEY_WRITE)
config = ConfigParser.ConfigParser()
print '正在打开IP.ini配置文件…'
config.readfp(open('IP.ini'))
IPAddress = config.get("school","IPAddress")
SubnetMask = config.get("school","SubnetMask")
GateWay = config.get("school","GateWay")
DNSServer1 = config.get("school","DNSServer1")
DNSServer2 = config.get("school","DNSServer2")
DNSServer = [DNSServer1,DNSServer2]print '配置文件内设定的信息如下,请核对:'
print 'IP地址:', IPAddress
print '子关掩码:', SubnetMask
print '默认网关:', GateWay
print '主DNS服务器:', DNSServer1
print '次DNS服务器:', DNSServer2
res = raw_input('现在,请您决定:输入1,则将配置文件写入系统;输入2,则将现有的系统设定还原为全部自动获取;否则程序退出:')
if str(res) == '1':
try:
_winreg.SetValueEx(hkey, 'EnableDHCP', None, _winreg.REG_DWORD, 0x00000000)
_winreg.SetValueEx(hkey, 'IPAddress', None, _winreg.REG_MULTI_SZ, [IPAddress])
_winreg.SetValueEx(hkey, 'SubnetMask', None, _winreg.REG_MULTI_SZ, [SubnetMask])
python 自动换ip_python实现自动更换ip的方法相关推荐
- python域名转ip_Python 实现域名解析为ip的方法
今天得了一批域名,需要把域名解析成ip 因为量比较大所以采用了多进程和队列的方式 from multiprocessing import Process,Queue,Pool import socke ...
- python requests 代理ip_python requests 测试代理ip
{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...
- 小猿圈python学习-Selenium爬虫之使用代理ip的方法
今天小猿圈给大家分享的是如何在爬取数据的时候防止IP被封,今天给大家分享两种方法,希望大家可以认真学习,再也不用 担心被封IP啦. 第一种: 降低访问速度,我们可以使用time模块中的sleep,使程 ...
- 将localhost换成自己电脑的ip的方法
本方法是基于的webpack vue的方法来演示的 //1.下载的ip的包 npm install ip -D //2.dev-server.js文件中const ip = require('ip') ...
- 撸一个自动换壁纸桌面应用
作为一名IT从业人员,一天当中陪着电脑的时间比陪家人的时间还要长.由于长时间盯着电脑屏幕,难免看厌了单调的桌面壁纸.本着换个壁纸,换种心情的目的,尝试了好几个自动换壁纸的windows桌面应用,要不是 ...
- android function封装,安卓按键精灵-自动换号封装函数
dim n,分割账号密码,账号,密码 Call 自动换号() Function 自动换号() n = File.ReadLine("/sdcard/misc/1.txt",1) T ...
- python自动投票源码(自动爬取更换ip)
import re import random import sys import time import datetime import threading from random import c ...
- Python零基础爬虫之回车桌面壁纸并实现自动换壁纸(内附完整源码)
前言 嗨喽,大家好,这里是魔王~ [课题]: Python零基础爬虫之回车桌面壁纸 [课题介绍]: 壁纸不应该只是一张图片,它应该是一门哲学 回车桌面网100000张无水印,高分辨率,电脑桌面壁纸, ...
- python简单代码运用到桌面壁纸_五行Python代码自动换你的电脑桌面壁纸(内附源码和exe)...
很多行友问行哥,Python能不能自动更换电脑壁纸呀,今天它来了 只需要一行代码,指定图片地址即可更换电脑桌面.加上壁纸文件夹路径,让你随机更换电脑桌面,带来不期而遇的新鲜.使用爬虫技术,自动下载壁纸 ...
- 【Python高级技能】超炫酷,电脑每天自动换壁纸,这个神器适合你。
导语 Hello,大家好!我是木木子! 今天闲着闲着--发现电脑的壁纸用了百八十年了,几个月都没换了.想着在有时间的时候换下壁纸换下心情✨! 大家是不是经常换壁纸都是下载一个壁纸的软件往下拉的? ...
最新文章
- ValueError: urls must start with a leading slash
- 中国省市区json分享
- 阿里云重磅推出物联网设备身份认证Link ID²
- 微信小程序实现转义换行符
- jQuery 树形控件 TreeView 的 Bug
- Chapter 1: 使用引用类型
- 这是一个定时器,定时执行一次,用在定时发送邮件
- 如何知道是哪个进程造成死锁?如何把这个进程杀掉?
- .net Response导出excel表格边框设置日期时间设置
- Tensorflow项目中--FLAGS=tf.flags.FLAGS
- VMware Workstation Pro安装教程图文详解
- `英语` 2022/8/28
- 京杭大运河北线疏浚穿越黄河地形UTM平面直角坐标系分析GIS模型建立
- SQL Server 2008 R2 安装 (转)
- 放弃理想,未必能成就现实
- IMX6ULL学习笔记(18)——GPIO中断
- 电脑丢失的dll文件怎么一键修复?修复dll方法分享
- 大数据开发工程师要求高么?有前景么
- 卷积码树状图怎么画_卷积码是什么 卷积码编码原理介绍【图文】
- u盘启动盘恢复计算机,U盘启动盘怎么恢复正常普通U盘?