#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>
$rkey = _getmac(3)
$Path = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
$Temp1 = RegRead($Path & $rkey, "ComponentId")
$Temp2 = RegRead($Path & $rkey, "MatchingDeviceId")
$Temp3 = RegRead($Path & $rkey, "DriverDesc")
TrayTip("MAC修改器", "正在修改网卡MAC地址,请稍候...", 10)
_modifiaMAC(makemac())
TrayTip("MAC修改器", "正在重新启动网卡,请稍候...", 10)
; _ReStart()
TrayTip("MAC修改器", "已将本机网卡的MAC地址更改为:"&_getmac(1), 10)
;函数设置
Func _getmac($n)
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For $objItem In $colItems
If StringLeft($objItem.MACAddress, 2) = 00 Then
$MACAdress = $objItem.MACAddress
$Key = StringMid($objItem.Caption, 6, 4)
$DriverDesc = $objItem.Description
EndIf
Next
$colName = $objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For $objName In $colName
$Name = $objName.Name
Next
Switch $n
Case 1
Return $MACAdress
Case 2
Return $Name
Case 3
Return $Key
Case 4
Return $DriverDesc
EndSwitch
EndFunc ;==>_getmac
Func makemac();产生随机地址
Local $tt="00000000"
$ip=StringRegExp(@IPAddress1,'.*\.(\d+)\.(\d+)',3)
If $ip[1]<100 And $ip[1]>9 Then $ip[1]="0"&$ip[1]
If $ip[1]<10 Then $ip[1]="0 "&$ip[1]
$tt=$tt&$ip[0]&$ip[1]
;MsgBox(0,0,$tt)
Return $tt
EndFunc ;==>makemac
Func _modifiaMAC($NewMAC) ;写入注册表值更改MAC
If $Temp1 = $Temp2 Then
RegWrite($Path & $rkey, "NetworkAddress", "REG_SZ", $NewMAC)
$PathNew = $Path & $rkey & "\Ndi\Params\NetworkAddress"
RegWrite($PathNew)
RegWrite($PathNew, "ParamDesc", "REG_SZ", "Network Address")
RegWrite($PathNew, "Default", "REG_SZ", $NewMAC)
RegWrite($PathNew, "Optional", "REG_SZ", "1")
Else
MsgBox(0, "", "检测到网卡修改后可能会出现问题!禁止修改!", 5)
_Exit()
EndIf
EndFunc ;==>_modifiaMAC
Func _ReStart() ;利用Devcon工具读取DEV.ID以及重新启动网络连接
If FileExists(@ScriptDir & "\devcon.exe") = 1 Then
RunWait(@ComSpec & ' /c devcon find pci\* > "' & @TempDir & '"\Dev.txt', "", @SW_HIDE)
$i = 0
$file = FileOpen(@TempDir & "\Dev.txt", 0)
While 1
$i = $i + 1
$lineWherther = FileReadLine($file)
$Wherther = StringSplit($lineWherther, ":")
If StringInStr($Wherther[2], $Temp3) Then ExitLoop
WEnd
$line = FileReadLine($file, $i)
$Split = StringSplit($line, "&")
FileClose($file)
RunWait("devcon disable *" & $Split[2] & "*", "", @SW_HIDE)
RunWait("devcon enable *" & $Split[2] & "*", "", @SW_HIDE)
Else
MsgBox(0, "错误", "缺少devcon.exe文件!" & @CRLF & "请重新启动主程序!", 5)
_Exit()
EndIf
EndFunc ;==>_ReStart
Func _Exit() ;退出事件
FileDelete(@TempDir & "\Dev.txt")
Exit
EndFunc ;==>_Exit