AU3根据MAC自动修改IP工具(请高手帮忙砍掉一个步骤)
AU3根据MAC自动修改IP工具每次运行的时候会让你选择“确定”和“取消”,很麻烦,想请高手帮忙把这一步骤去掉,改成运行后直接
根据MAC修改IP,不做选择,谢谢了,代码如下
下面还有成品,AU3源码,可以直接编辑的
#NoTrayIcon
$g_szVersion = "MacToIp 2.3"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
HotKeySet("{ESC}", "_Terminate")
Dim $Msg = '计算机修改信息。' & @CRLF & @CRLF
If Not @OSType = "WIN32_NT" OR Not @OSLang = "0804" then;判断是否支持此系统
MsgBox(16, "错误……Make By Amu", "本工具不支持此系统", 10)
Exit
EndIf
;设置配置文件路径
$Mac2Ip = "Mac2Ip.ini"
If Not FileExists($Mac2Ip) Then
$Mac2Ip = @ScriptDir & "\Mac2Ip.ini"
If Not FileExists($Mac2Ip) Then
$Mac2Ip = @WorkingDir & "\Mac2Ip.ini"
EndIf
EndIf
If Not FileExists($Mac2Ip) Then
MsgBox(64, "错误……Make By Amu", '没有找到配置文件"' & $Mac2Ip & '"' & @CRLF & '或"' & $Mac2Ip & '"不在同一目录下', 15)
Exit
EndIf
$LocMAC = _GetLocalMAC()
If $LocMAC = 0 Then
MsgBox(64, "错误……Make By Amu", '找不到本机MAC地址,' & @CRLF & '请检查本机配置!', 15)
Exit
Else
For $m = 1 to $LocMAC
$info = IniRead($Mac2Ip, "Mac2Ip", $LocMAC[$m], "")
If $info <> "" Then ExitLoop
Next
EndIf
$info = StringSplit($info, "|")
If $info < 2 Then Dim $info
$PcName = _StringIsComputerName($info)
While @error
$info = InputBox("输入的新计算机名格式不对。", '请重新设置计算机名!' & @CRLF & @CRLF & '标准名称可以含有字母(a-z, A-Z)、数字(0-9)和连字符(-),但不能含有空格或句号(.)。名称可能不完全是数字。', "", " M63")
If @error Then _Terminate()
$PcName = _StringIsComputerName($info)
If Not @error Then ExitLoop
WEnd
$PcName = $info
$Msg = $Msg & "计算机名 ....: " & $PcName & @CRLF
$ipAdd = _StringIsIP($info)
While @error
$info = InputBox("IP地址格式错误", "请重新输入IP地址!", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$ipAdd = _StringIsIP($info)
If Not @error Then ExitLoop
WEnd
$Msg = $Msg & "IP地址 ....: " & $ipAdd & @CRLF
$Mask = _StringIsIP(IniRead($Mac2Ip, "Setting", "Mask", "255.255.255.0"))
While @error
$Mask = InputBox("子网掩码格式错误", "请重新输入子网掩码!", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$Mask = _StringIsIP($Mask)
If Not @error Then ExitLoop
WEnd
$Msg = $Msg & "子网掩码 ....: " & $Mask & @CRLF
$Gateway = _StringIsIP(IniRead($Mac2Ip, "Setting", "GateWay", "192.168.0.1"))
While @error
$Gateway = InputBox("默认网关格式错误", "请重新输入网关!", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$Gateway = _StringIsIP($Gateway)
If Not @error Then ExitLoop
WEnd
$Msg = $Msg & "默认网关 ....: " & $Gateway & @CRLF
$CsKey = IniReadSection($Mac2Ip, "Cs15Key")
If @error Then
$CsKey = 0
Else
$n = Random(1, $CsKey, 1)
$CsKey = IniRead($Mac2Ip, "Cs15Key", $n, "1234567890123")
EndIf
If $CsKey <> 0 Then $Msg = $Msg & "CS-CDKEY ....: " & $CsKey & @CRLF
$OK = MsgBox(33,"请确认......Make By Amu", $Msg, 5)
If $OK = 2 Then_Terminate()
$SetName = _SetComputerName($PcName)
$SetIpAdd = _SetIPAddress($ipAdd, $Mask, $Gateway)
If $CsKey <> 0 Then RegWrite("HKCU\Software\Valve\CounterStrike\Settings", "key", "REG_SZ", $CsKey)
Func _SetIPAddress($ipAdd, $Mask = "255.255.255.0", $Gateway = "")
$Return = 0
$ipAdd = _StringIsIP($ipAdd)
If $ipAdd = "" Then $Return = $Return + 1
$Mask = _StringIsIP($Mask)
If $Mask = "" Then $Return = $Return + 2
$Gateway = _StringIsIP($Gateway)
If $Gateway = "" Then $Return = $Return + 4
Dim $LocalIPAddress = [$ipAdd]
Dim $strSubnetMask = [$Mask]
Dim $strGateway = [$Gateway]
Dim $strGatewayMetric =
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colNetAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
If IsObj($colNetAdapters) Then
For $objNetAdapter in $colNetAdapters
If BitAND($Return, 1) = 0 AND BitAND($Return, 2) = 0 Then $objNetAdapter.EnableStatic($LocalIPAddress, $strSubnetMask)
If BitAND($Return, 4) = 0 Then $objNetAdapter.SetGateways($strGateway, $strGatewayMetric)
Next
EndIf
Return $Return
EndFunc;_SetIPAddress修改IP地址
Func _SetComputerName($strComputerName)
$SetKey1 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\"
$CtrlKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\"
$Return = RegWrite ($SetKey1 & "Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $strComputerName)
RegWrite ($SetKey1 & "Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $strComputerName)
RegWrite ($SetKey1 & "Services\Tcpip\Parameters", "Hostname", "REG_SZ", $strComputerName)
RegWrite ($CtrlKey & "Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $strComputerName)
RegWrite ($CtrlKey & "Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $strComputerName)
RegWrite ($CtrlKey & "Services\Tcpip\Parameters", "Hostname", "REG_SZ", $strComputerName)
Return $Return
EndFunc;_SetComputerName修改计算机名
Func _GetLocalMAC()
Dim $aNULL =
$MAC = Chr(13)
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
If IsObj($colNicConfigs) Then
For $objItem In $colNicConfigs
$objNic = $objWMIService.Get ("Win32_NetworkAdapter.DeviceID=" & $objItem.Index)
$MAC = $MAC & Chr(10) & $objNic.MACAddress
Next
$MAC = StringReplace($MAC, Chr(13) & Chr(10), "")
If StringInStr($MAC, ":") = 0Then
SetError(2)
Return $aNULL
Else
$MAC = StringReplace($MAC, ":", "-")
Return StringSplit($MAC, Chr(10))
EndIf
Else
SetError(1)
Return $aNULL
EndIf
EndFunc;_GetLocalMAC获取本地MAC地址
Func _StringIsComputerName($strComputerName, $ShowMsgBox=1)
If $strComputerName = "" OR StringLen($strComputerName) > 63 Then
$err = '输入的新计算机名格式不对。标准名称可以含有字母(a-z, A-Z)、数字(0-9)和连字符(-),但不能含有空格或句号(.)。名称可能不完全是数字。'
SetError(1)
Return 0
ElseIf StringIsDigit($strComputerName) = 1 Then
If @OSVersion = "WIN_2000" Then
$Title = "网络标识"
Else
$Title = "计算机名更改"
EndIf
If $ShowMsgBox=1 Then MsgBox(48, $Title, '新计算机名 "' & $strComputerName & '" 是一个数字。名称不应是数字。')
SetError(2)
Return 0
EndIf
$NoText = '`~!@#$. ^&*()=+[]{}\|;:' & Chr(39) & '",<>/?'
For $i = 1 To StringLen($strComputerName)
If StringInStr($NoText, StringMid($strComputerName, $i, 1)) <> 0 Then
If @OSVersion = "WIN_2000" Then
$Title = "网络标识"
$Text = '新计算机名 "' & $strComputerName & '" 包括非法的字符。'
Else
$Title = "计算机名更改"
$Text = '新计算机名 "' & $strComputerName & '" 包括不允许的字符。不允许的字符包括 ` ~ ! @ # $^ & * ( ) = + [ ] { } \ | ; : ' & Chr(39) & ' " , < > / 和 ?'
EndIf
If $ShowMsgBox = 1 Then MsgBox(48, $Title, $Text)
SetError(3)
Return 0
EndIf
Next
If $ShowMsgBox <> 1 Then Return 1
$Text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
For $i = 1 To StringLen($strComputerName)
If StringInStr($Text, StringMid($strComputerName, $i, 1)) = 0 Then
If @OSVersion = "WIN_2000" Then
$Title = "网络标识"
Else
$Title = "计算机名更改"
EndIf
$iMsgBoxAnswer = MsgBox(48+4, $Title, '计算机名 "' & $strComputerName & '" 含有一个或一个以上非标准字符。标准字符包括字母(A-Z,a-z)、数字(0-9)和连字符(-)。如使用非标准字符名称,除非您所属网络使用 Microsoft DNS 服务器,否则其他用户就会在网络上找不到您的计算机。要使用这个非标准名称吗?')
If $iMsgBoxAnswer = 6 Then
Return 1
Else
SetError(4)
Return 0
EndIf
EndIf
Next
EndFunc; _StringIsComputerName判断计算机名是否正确
Func _StringIsIP($strIP)
$str = StringSplit($strIP, ".")
If $str <> 4 Then
SetError(1)
return ('')
ElseIf StringIsDigit($str) <> 1 OR StringIsDigit($str) <> 1 OR StringIsDigit($str) <> 1 OR StringIsDigit($str) <> 1 Then
SetError(2)
return ('')
ElseIf $str > 255 OR $str > 255 OR $str > 255 OR $str > 255 Then
SetError(3)
return ('')
Else
return (Int($str) & "." & Int($str) & "." & Int($str) & "." & Int($str))
EndIf
EndFunc;_StringIsIP判断IP格式是否正确
Func _Terminate()
ToolTip("正在退出……"&@CR&"谢谢使用"&@CR&@YEAR&"年"&@MON&"月"&@MDAY&"日",@DesktopWidth-90,@DesktopHeight-71)
Sleep(3000)
Exit 0
EndFunc 最加个如果没有配置文件就自动生成,没有MAC就加 我帮你改了一下程序,可以连DNS一起写上去的。
INI文件
Mask="255.255.255.0"
GateWay="192.168.0.254"
dns1=202.96.128.86
dns2="202.96.128.143"
;按以下格式添加MAC地址对应关系,稍后发布扫描器。
00-30-67-26-a5-86=A016|192.168.0.16#NoTrayIcon
$g_szVersion = "MacToIp 2.3"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
Dim $Msg = '计算机修改信息。' & @CRLF & @CRLF
If Not @OSType = "WIN32_NT" OR Not @OSLang = "0804" then;判断是否支持此系统
MsgBox(16, "错误", "本工具不支持此系统", 10)
Exit
EndIf
;设置配置文件路径
$Mac2Ip = "Mac2Ip.ini"
If Not FileExists($Mac2Ip) Then
$Mac2Ip = @ScriptDir & "\Mac2Ip.ini"
If Not FileExists($Mac2Ip) Then
$Mac2Ip = @WorkingDir & "\Mac2Ip.ini"
EndIf
EndIf
$LocMAC = _GetLocalMAC()
If $LocMAC = 0 Then
MsgBox(64, "错误", '找不到本机MAC地址,' & @CRLF & '请检查本机配置!', 15)
Exit
Else
For $m = 1 to $LocMAC
$info = IniRead($Mac2Ip, "Mac2Ip", $LocMAC[$m], "")
If $info <> "" Then ExitLoop
Next
EndIf
$info = StringSplit($info, "|")
If $info < 2 Then Dim $info
$PcName = _StringIsComputerName($info)
$PcName = $info
$Msg = $Msg & "计算机名 : " & $PcName & @CRLF
$ipAdd = _StringIsIP($info)
$Msg = $Msg & "IP地址 : " & $ipAdd & @CRLF
$Mask = _StringIsIP(IniRead($Mac2Ip, "Setting", "Mask", "255.255.255.0"))
$Msg = $Msg & "子网掩码 : " & $Mask & @CRLF
$Gateway = _StringIsIP(IniRead($Mac2Ip, "Setting", "GateWay", "192.168.0.1"))
$Msg = $Msg & "默认网关 : " & $Gateway & @CRLF
$DNS1 = _STRINGISIP(IniRead($MAC2IP, "SETTING","DNS1","202.96.128.86"))
$MSG = $MSG & " DNS1:" & $DNS1 & @CRLF
$DNS2 = _STRINGISIP(IniRead($MAC2IP, "SETTING","DNS2","202.96.128.86"))
$MSG = $MSG & " DNS1:" & $DNS2 & @CRLF
$OK = MsgBox(33,"用MAC自动更新IP和计算机名 FOR WINXP", $Msg, 3)
$SetName = _SetComputerName($PcName)
$SetIpAdd = _SetIPAddress($ipAdd, $Mask, $Gateway)
;--------------------_SetIPAddress修改IP地址-----------------------------
Func _SetIPAddress($ipAdd, $Mask = "255.255.255.0", $Gateway = "")
$Return = 0
$ipAdd = _StringIsIP($ipAdd)
If $ipAdd = "" Then $Return = $Return + 1
$Mask = _StringIsIP($Mask)
If $Mask = "" Then $Return = $Return + 2
$Gateway = _StringIsIP($Gateway)
If $Gateway = "" Then $Return = $Return + 4
$netcard = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}", 2)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $netcard, "NameServer", "REG_SZ", $DNS1 & "," & $DNS2)
Dim $LocalIPAddress = [$ipAdd]
Dim $strSubnetMask = [$Mask]
Dim $strGateway = [$Gateway]
Dim $strGatewayMetric =
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colNetAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
If IsObj($colNetAdapters) Then
For $objNetAdapter in $colNetAdapters
If BitAND($Return, 1) = 0 AND BitAND($Return, 2) = 0 Then $objNetAdapter.EnableStatic($LocalIPAddress, $strSubnetMask)
If BitAND($Return, 4) = 0 Then $objNetAdapter.SetGateways($strGateway, $strGatewayMetric)
Next
EndIf
Return $Return
EndFunc
;--------------------------------------------------------------------------
;-----------------_SetComputerName修改计算机名-----------------------------
Func _SetComputerName($strComputerName)
$SetKey1 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\"
$CtrlKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\"
$Return = RegWrite ($SetKey1 & "Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $strComputerName)
RegWrite ($SetKey1 & "Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $strComputerName)
RegWrite ($SetKey1 & "Services\Tcpip\Parameters", "Hostname", "REG_SZ", $strComputerName)
RegWrite ($CtrlKey & "Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $strComputerName)
RegWrite ($CtrlKey & "Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $strComputerName)
RegWrite ($CtrlKey & "Services\Tcpip\Parameters", "Hostname", "REG_SZ", $strComputerName)
Return $Return
EndFunc
;---------------------------------------------------------------------------
;-----------------_GetLocalMAC获取本地MAC地址-------------------------------
Func _GetLocalMAC()
Dim $aNULL =
$MAC = Chr(13)
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
If IsObj($colNicConfigs) Then
For $objItem In $colNicConfigs
$objNic = $objWMIService.Get ("Win32_NetworkAdapter.DeviceID=" & $objItem.Index)
$MAC = $MAC & Chr(10) & $objNic.MACAddress
Next
$MAC = StringReplace($MAC, Chr(13) & Chr(10), "")
If StringInStr($MAC, ":") = 0Then
SetError(2)
Return $aNULL
Else
$MAC = StringReplace($MAC, ":", "-")
Return StringSplit($MAC, Chr(10))
EndIf
Else
SetError(1)
Return $aNULL
EndIf
EndFunc
;--------------------------------------------------------------------------
;---------------_StringIsComputerName判断计算机名是否正确------------------
Func _StringIsComputerName($strComputerName, $ShowMsgBox=1)
If $strComputerName = "" OR StringLen($strComputerName) > 63 Then
$err = '输入的新计算机名格式不对。标准名称可以含有字母(a-z, A-Z)、数字(0-9)和连字符(-),但不能含有空格或句号(.)。名称可能不完全是数字。'
SetError(1)
Return 0
ElseIf StringIsDigit($strComputerName) = 1 Then
If @OSVersion = "WIN_2000" Then
$Title = "网络标识"
Else
$Title = "计算机名更改"
EndIf
If $ShowMsgBox=1 Then MsgBox(48, $Title, '新计算机名 "' & $strComputerName & '" 是一个数字。名称不应是数字。')
SetError(2)
Return 0
EndIf
$NoText = '`~!@#$. ^&*()=+[]{}\|;:' & Chr(39) & '",<>/?'
For $i = 1 To StringLen($strComputerName)
If StringInStr($NoText, StringMid($strComputerName, $i, 1)) <> 0 Then
If @OSVersion = "WIN_2000" Then
$Title = "网络标识"
$Text = '新计算机名 "' & $strComputerName & '" 包括非法的字符。'
Else
$Title = "计算机名更改"
$Text = '新计算机名 "' & $strComputerName & '" 包括不允许的字符。不允许的字符包括 ` ~ ! @ # $^ & * ( ) = + [ ] { } \ | ; : ' & Chr(39) & ' " , < > / 和 ?'
EndIf
If $ShowMsgBox = 1 Then MsgBox(48, $Title, $Text)
SetError(3)
Return 0
EndIf
Next
If $ShowMsgBox <> 1 Then Return 1
$Text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
For $i = 1 To StringLen($strComputerName)
If StringInStr($Text, StringMid($strComputerName, $i, 1)) = 0 Then
If @OSVersion = "WIN_2000" Then
$Title = "网络标识"
Else
$Title = "计算机名更改"
EndIf
$iMsgBoxAnswer = MsgBox(48+4, $Title, '计算机名 "' & $strComputerName & '" 含有一个或一个以上非标准字符。标准字符包括字母(A-Z,a-z)、数字(0-9)和连字符(-)。如使用非标准字符名称,除非您所属网络使用 Microsoft DNS 服务器,否则其他用户就会在网络上找不到您的计算机。要使用这个非标准名称吗?')
If $iMsgBoxAnswer = 6 Then
Return 1
Else
SetError(4)
Return 0
EndIf
EndIf
Next
EndFunc
;--------------------------------------------------------------------------------
;-----------------_StringIsIP判断IP格式是否正确----------------------------------
Func _StringIsIP($strIP)
$str = StringSplit($strIP, ".")
If $str <> 4 Then
SetError(1)
return ('')
ElseIf StringIsDigit($str) <> 1 OR StringIsDigit($str) <> 1 OR StringIsDigit($str) <> 1 OR StringIsDigit($str) <> 1 Then
SetError(2)
return ('')
ElseIf $str > 255 OR $str > 255 OR $str > 255 OR $str > 255 Then
SetError(3)
return ('')
Else
return (Int($str) & "." & Int($str) & "." & Int($str) & "." & Int($str))
EndIf
EndFunc
;--------------------------------------------------------------------------------- 谢谢楼主提供... 谢谢楼主提供... 谢谢楼主提供...
页:
[1]