硬广 :
提供ahk, python 自动化脚本服务:
我的qq: 513278236
微信: happy_lizhe
我的淘宝店: AHK, python 自动化操作
自动调整IP 直至能用。
AdapterName := "以太网"
Loop
{
FileDelete, temp.bat
Random, RanIP , 0, 255
cmd := "@echo off`nnetsh interface ipv4 set address name=""" . AdapterName . """ static 192.168.0." . RanIP . " 255.255.255.0 192.168.0.1"
FileAppend, %cmd%, temp.bat
RunWait, temp.bat
FileDelete, temp.bat
Sleep,5000
RunWait, ping www.baidu.com,,hide UseErrorLevel, OutputVarPID
IP := GetLocalIPByAdaptor(AdapterName)
MsgBox, 0, , ErrorLevel = %ErrorLevel% RanIP = %RanIP% IP = %IP%, 3
if(ErrorLevel = 0)
{
break
}
}
GetLocalIPByAdaptor(adaptorName) {
objWMIService := ComObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" adaptorName "'")._NewEnum, colItems[objItem]
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE InterfaceIndex = '" objItem.InterfaceIndex "'")._NewEnum, colItems[objItem]
Return objItem.IPAddress[0]
}
ExitApp
网友评论