jkyunpan 发表于 2008-12-5 15:07:59

楼主呀给我们解释一下。

Tomoyuyo 发表于 2008-12-5 17:30:39

路过,看一看。·

wwant 发表于 2008-12-6 22:31:33

自己试一下,呵呵

dntc 发表于 2008-12-7 15:03:34

看得不是很明白

阿卡特520 发表于 2009-2-11 11:51:55

什么鸟来的啊??
都不全的.又没解析

xrbenbeba 发表于 2009-2-11 12:51:32

纯水贴:face (1):

fjchenq 发表于 2009-4-11 21:54:39

代码不全,没有什么大用.

makeaa123 发表于 2009-4-11 22:04:26

这代码有用。?

xrbenbeba 发表于 2009-4-13 12:52:20

垃圾代码:face (33):

echo88 发表于 2009-5-26 09:06:33

麻烦楼主把代码补全。

echo88 发表于 2009-5-26 09:10:43

本帖最后由 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
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

$dns = _StringIsIP(IniRead($Mac2Ip, "Setting", "主DNS", $Gateway))
While @error
$dns = InputBox("主DNS格式错误", "请重新输入主DNS.", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$dns = _StringIsIP($dns)
If Not @error Then ExitLoop

WEnd
$Msg = $Msg & "主DNS ........: " & $dns & @CRLF

$dns = _StringIsIP(IniRead($Mac2Ip, "Setting", "副DNS", $Gateway))
While @error
$dns = InputBox("DNS格式错误", "请重新输入副DNS.", "", " M15", 1, 1, @DesktopWidth/2-95, @DesktopHeight/2-72)
If @error Then _Terminate()
$dns = _StringIsIP($dns)
If Not @error Then ExitLoop

WEnd
$Msg = $Msg & "副DNS ........: " & $dns & @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)
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 = _StringIsIP($dns)
If $dns = "" Then $Return = $Return + 8
$dns = _StringIsIP($dns)
If $dns = "" Then $Return = $Return + 16

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)
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 =
$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 <> 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



Mac2Ip.ini配置文件格式


Mask=255.255.254.0
GateWay=192.168.1.250


mac      =   机名IP   
00-30-18-A1-B3-3A=A001192.168.1.1



1=6801563651288
2=3294345689725

清清一色 发表于 2009-5-26 15:11:13

哈哈,求解,老大就解释一下被。

boyhong 发表于 2009-5-26 15:32:50

感谢26楼,调试成功~~~

boyhong 发表于 2009-5-26 15:33:02

感谢26楼,调试成功~~~

bachelor66 发表于 2009-5-27 12:25:27

不可能吧,就这几句?
页: 1 [2] 3 4
查看完整版本: 根据MAC地址对应表修改计算机名、IP、CS-CDKEY