本帖最后由 echo88 于 2009-5-26 09:18 编辑
google了一下,找到了完整的代码:
#NoTrayIcon
$g_szVersion = "MacToIp 2.3"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
HotKeySet("{ESC}", "_Terminate")
dim $dns[2]
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] = 0 Then
MsgBox(64, "错误……Make By Amu", '找不到本机MAC地址,' & @CRLF & '请检查本机配置!', 15)
Exit
Else
For $m = 1 to $LocMAC[0]
$info = IniRead($Mac2Ip, "Mac2Ip", $LocMAC[$m], "")
If $info <> "" Then ExitLoop
Next
EndIf
$info = StringSplit($info, "|")
If $info[0] < 2 Then Dim $info[3]
$PcName = _StringIsComputerName($info[1])
While @error
$info[1] = InputBox("输入的新计算机名格式不对。", '请重新设置计算机名!' & @CRLF & @CRLF & '标准名称可以含有字母(a-z, A-Z)、数字(0-9)和连字符(-),但不能含有空格或句号(.)。名称可能不完全是数字。', "", " M63")
If @error Then _Terminate()
$PcName = _StringIsComputerName($info[1])
If Not @error Then ExitLoop
WEnd
$PcName = $info[1]
$Msg = $Msg & "计算机名 ....: " & $PcName & @CRLF
$ipAdd = _StringIsIP($info[2])
While @error
$info[2] = InputBox("IP地址格式错误", "请重新输入IP地址!", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$ipAdd = _StringIsIP($info[2])
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
$dns[0] = _StringIsIP(IniRead($Mac2Ip, "Setting", "主DNS", $Gateway))
While @error
$dns[0] = InputBox("主DNS格式错误", "请重新输入主DNS.", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$dns[0] = _StringIsIP($dns[0])
If Not @error Then ExitLoop
WEnd
$Msg = $Msg & "主DNS ........: " & $dns[0] & @CRLF
$dns[1] = _StringIsIP(IniRead($Mac2Ip, "Setting", "副DNS", $Gateway))
While @error
$dns[1] = InputBox("DNS格式错误", "请重新输入副DNS.", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$dns[1] = _StringIsIP($dns[1])
If Not @error Then ExitLoop
WEnd
$Msg = $Msg & "副DNS ........: " & $dns[1] & @CRLF
$CsKey = IniReadSection($Mac2Ip, "Cs15Key")
If @error Then
$CsKey = 0
Else
$n = Random(1, $CsKey[0][0], 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)
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
$dns[0] = _StringIsIP($dns[0])
If $dns[0] = "" Then $Return = $Return + 8
$dns[1] = _StringIsIP($dns[1])
If $dns[1] = "" Then $Return = $Return + 16
Dim $LocalIPAddress[1] = [$ipAdd]
Dim $strSubnetMask[1] = [$Mask]
Dim $strGateway[1] = [$Gateway]
Dim $strGatewayMetric[1] = [1]
$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)
If BitAND($Return, 8) = 0 and BitAND($Return, 16) = 0 Then $objNetAdapter.SetDNSServerSearchOrder($dns)
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[1] = [0]
$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, ":") = 0 Then
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[0] <> 4 Then
SetError(1)
return ('')
ElseIf StringIsDigit($str[1]) <> 1 OR StringIsDigit($str[2]) <> 1 OR StringIsDigit($str[3]) <> 1 OR StringIsDigit($str[4]) <> 1 Then
SetError(2)
return ('')
ElseIf $str[1] > 255 OR $str[2] > 255 OR $str[3] > 255 OR $str[4] > 255 Then
SetError(3)
return ('')
Else
return (Int($str[1]) & "." & Int($str[2]) & "." & Int($str[3]) & "." & Int($str[4]))
EndIf
EndFunc ;_StringIsIP判断IP格式是否正确
Func _Terminate()
ToolTip("正在退出……"&@CR&"谢谢使用"&@CR&@YEAR&"年"&@MON&"月"&@MDAY&"日",@DesktopWidth-90,@DesktopHeight-71)
Sleep(3000)
Exit 0
EndFunc
Mac2Ip.ini配置文件格式
[Setting]
Mask=255.255.254.0
GateWay=192.168.1.250
[Mac2Ip]
mac = 机名IP
00-30-18-A1-B3-3A=A001192.168.1.1
[Cs15Key]
1=6801563651288
2=3294345689725 |