为AMU的MacToIp写的扫描程序(以nbtscan为核心
/attachment/<a href="attachment/Uploadfiles/2007-2/226149874.rar">Uploadfiles/2007-2/226149874.rar</a><br />下载放到脚本目录,不然会提示缺少文件。 <p>扫描出来虽然有好多项,但保存的时候格式为AMU的MacToIp 2.3的配置文件格式</p><p>参照:<a href="http://autoit.8800.org/ShowPost.asp?id=1109" target="_blank">[原创]根据MAC地址对应表修改计算机名、IP、CS-CDKEY。</a> 。</p><p>下面为源代码:</p><p>opt("TrayAutoPause",0)<br />$g_szVersion = "MacScaner ver 1.02 for AMU MacToIp 2.3 by LuRen"<br />If WinExists($g_szVersion) Then Exit<br />#i nclude <GUIConstants.au3><br />#i nclude <GuiStatusBar.au3><br />#i nclude <file.au3><br />#i nclude <GuiListView.au3><br />$dllsize = FileGetSize(@ScriptDir & "\cygwin1.dll")<br />$exesize = FileGetSize(@ScriptDir & "\nbtscan.exe")<br />If $dllsize <> 1140617 or $exesize <> 84736 Then<br /> $msgbox = msgbox(8192+16+4,"错误","缺少关键文件,是否要到 <a href="http://autoit.8800.org/" target="_blank">HTTP://AUTOIT.8800.ORG</a> 发贴求助!")<br /> IF $msgbox = 6 Then<br /> run(@ProgramFilesDir & "\Internet Explorer\IEXPLORE.EXE <a href="http://autoit.8800.org/" target="_blank">HTTP://AUTOIT.8800.ORG</a>")<br /> EndIf<br /> Exit<br />EndIf<br />$Form1 = GUICreate($g_szVersion, 570 , 320,-1,-1)<br />$Button1 = GUICtrlCreateButton("扫描", 500, 20, 60,22 )<br />$Button2 = GUICtrlCreateButton("删除", 500, 50, 60,22)<br />$Button3 = GUICtrlCreateButton("清空", 500, 80, 60,22)<br />$Button4 = GUICtrlCreateButton("整理", 500, 110, 60, 22)<br />$Button5 = GUICtrlCreateButton("保存", 500, 140, 60,22)<br />$Button6 = GUICtrlCreateButton("退出", 500, 170, 60, 22)<br />$Combo1 = GUICtrlCreateCombo("",1,1,490,20,0x0003)<br />Dim $Description,$ServiceName,$cards,$myipaddress,$mygeteway,$mysubnetmask,$mydns<br />For $i= 1 to 4<br /> $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards",$i)<br /> If @error <> 0 then<br /> ExitLoop<br /> Else<br /> $Description[$i] = regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $var ,"Description")<br /> $ServiceName[$i] = regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $var ,"ServiceName")<br /> If stringlen($Description[$i]) > 0 Then<br /> $cards = $cards & $Description[$i] & "|"<br /> EndIf<br /> EndIf<br />Next<br />GUICtrlSetData($Combo1,$cards, $Description)<br />getnetworkconfig($Description)<br />$label1 = GUICtrlCreatelabel("", 500, 200, 60, 22,0x0201 )<br />$listview1 = GUICtrlCreateListView("IP Address |NetBIOS Name |Server |User |MAC Address ",1,20,490 ,280 )<br />Local $gui, $StatusBar1<br />Local $a_PartsRightEdge = <br />Local $a_PartsText = ["本机名:" & @ComputerName,"本机IP:" & $myipaddress,"本机MAC:"& _GetMACFromIP($myipaddress),"技术支持:Http://AutoIt.8800.org"]<br />$StatusBar1 = _GUICtrlStatusBarCreate ($Form1, $a_PartsRightEdge, $a_PartsText)</p><p>GUISetState(@SW_SHOW)</p><p>While 1<br /> $msg = GuiGetMsg()<br /> Select<br /> Case $msg = $GUI_EVENT_CLOSE or $msg = $Button6<br /> ExitLoop<br /> Case $msg = $Button1<br /> scan()<br /> Case $msg = $Button2<br /> deleteitem()<br /> Case $msg = $Button3<br /> clearall()<br /> Case $msg = $Button4<br /> clearup()<br /> Case $msg = $Button5<br /> saveas()<br /> Case $msg = $Combo1<br /> getnetworkconfig(GUICtrlRead($Combo1))<br /> _GUICtrlStatusBarSetText($StatusBar1, "本机IP:" & $myipaddress,1)<br /> _GUICtrlStatusBarSetText($StatusBar1, "本机MAC:"& _GetMACFromIP($myipaddress),2)<br /> case $msg = $listview1<br /> Dim $B_DESCENDING<br /> _GUICtrlListViewSort($listview1, $B_DESCENDING, GUICtrlGetState($listview1))<br /> EndSelect<br />WEnd<br />Exit<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func OnAutoItExit() ;;;脚本退出时清理临时文件<br />FileDelete(@TempDir & "\scaneripadd.txt")<br />EndFunc<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func _GetMACFromIP($sIP) ;;根椐IP取MAC,此程序中只是为了取本机的MAC用以显示在状态栏中<br /> Local $MAC, $MACSize<br /> Local $i, $s, $r, $iIP<br /> $MAC = DllStructCreate("byte")<br /> $MACSize = DllStructCreate("int")<br /> DllStructSetData($MACSize, 1, 6)<br /> $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)<br /> $iIP = $r<br /> $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))<br /> $s = ""<br /> For $i = 0 To 5<br /> If $i Then $s = $s & "-"<br /> $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)<br /> Next<br /> Return $s<br />EndFunc ;==>_GetMACFromIP<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func scan() ;;;扫描,创建列表<br />$pid = Run(@ComSpec & ' /c "' & @ScriptDir & '\nbtscan.exe" -r ' & $myipaddress & "/" & CountSubnetMaskBit($mysubnetmask) & ">" & @TempDir & "\scaneripadd.txt",@TempDir,@SW_HIDE)<br />$x = True<br /> Do<br /> If $x Then<br /> GUICtrlSetData($label1,"扫描中")<br /> GUICtrlSetBkColor($label1,0x00FF00)<br /> Else<br /> GUICtrlSetBkColor($label1,-1)<br /> EndIf<br /> $x = not $x<br /> sleep(300)<br /> Until Not ProcessExists($pid)<br /> GUICtrlSetBkColor($label1,-1)<br /> GUICtrlSetData($label1,"处理中")<br /> dim $arrayiplist<br />;~ dim $arrayiplist<br /> If Not _FileReadToArray(@tempdir & "\scaneripadd.txt",$arrayiplist) Then<br /> SetError(1)<br /> Return -1<br /> EndIf<br /> For $x = $arrayiplist to 1 step -1<br /> $line = $arrayiplist[$x]<br /> If $line = "------------------------------------------------------------------------------" Then<br /> ExitLoop<br /> ElseIf stringlen($line) = 0 Then<br /> ContinueLoop<br /> Else<br /> $ipaddress = StringStripWS(stringleft($line,17),3)<br /> $netbios> $server = StringStripWS(stringmid($line,35,10),3)<br /> $user = StringStripWS(stringmid($line,45,17),3)<br /> $macaddress = StringUpper(stringmid($line,62,17))<br /> GUICtrlCreateListViewItem($ipaddress & "|" & $netbios> EndIf<br /> Next<br /> GUICtrlSetData($label1,"完成")<br />EndFunc ;==>scan<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func CountSubnetMaskBit($subnetmask) ;;;;统计子网掩码的位数<br /> $subnetmasksp = StringSplit($subnetmask, ".")<br /> If $subnetmasksp <> 4 Then<br /> SetError(1)<br /> Return 32<br /> EndIf<br /> $bit = 0<br /> For $x = 1 To 4<br /> If $subnetmasksp[$x] = 255 Then<br /> $bit = $bit + 8<br /> ElseIf $subnetmasksp[$x] = 254 Then<br /> $bit = $bit + 7<br /> ElseIf $subnetmasksp[$x] = 252 Then<br /> $bit = $bit + 6<br /> ElseIf $subnetmasksp[$x] = 248 Then<br /> $bit = $bit + 5<br /> ElseIf $subnetmasksp[$x] = 240 Then<br /> $bit = $bit + 4<br /> ElseIf $subnetmasksp[$x] = 224 Then<br /> $bit = $bit + 3<br /> ElseIf $subnetmasksp[$x] = 192 Then<br /> $bit = $bit + 2<br /> ElseIf $subnetmasksp[$x] = 128 Then<br /> $bit = $bit + 1<br /> ElseIf $subnetmasksp[$x] <> 0 Then<br /> SetError(1)<br /> Return 32<br /> EndIf<br /> Next<br /> If $bit >= 1 And $bit <= 32 Then<br /> Return $bit<br /> Else<br /> SetError(1)<br /> Return 32<br /> EndIf<br />EndFunc ;==>CountSubnetMaskBit<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func clearall() ;;;清空<br /> _GUICtrlListViewDeleteAllItems($listview1)<br /> guictrlsetdata($label1,"")<br />EndFunc ;==>clearall<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func clearup() ;;;整理重复<br /> Local $count<br /> $count = _GUICtrlListViewGetItemCount($listview1)<br /> If $count Then<br /> dim $itemarray[$count]<br /> EndIf<br /> for $x = 0 to $count - 1<br /> $itemarray[$x] = _GUICtrlListViewGetItemText($listview1,$x)<br /> Next<br /> For $x = 0 to $count - 1<br /> For $y = $x + 1 to $count - 1<br /> If $itemarray[$x] = $itemarray[$y] Then<br /> $itemarray[$y] = ""<br /> EndIf<br /> Next<br /> Next<br /> _GUICtrlListViewDeleteAllItems($listview1)<br /> For $x = 0 to $count - 1<br /> If StringLen($itemarray[$x]) > 0 then<br /> GUICtrlCreateListViewItem($itemarray[$x],$listview1)<br /> EndIf<br /> Next<br /> guictrlsetdata($label1,"")<br />EndFunc ;==>clearup<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func deleteitem() ;;;;删除一项<br /> If _GUICtrlListViewGetSelectedCount($listview1) Then<br /> _GUICtrlListViewDeleteItemsSelected($listview1)<br /> EndIf<br />EndFunc ;==>deleteitem<br />;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func saveas() ;;;保存<br /> Local $count,$lines<br /> $count = _GUICtrlListViewGetItemCount($listview1)<br /> If $count >=1 Then<br /> Local $savetextarray<br /> For $x = 0 to $count - 1<br /> $savetextarray = _GUICtrlListViewGetItemTextArray($listview1,$x)<br /> $lines = $lines & $savetextarray & "=" & $savetextarray & "|" & $savetextarray & @CRLF<br /> Next<br /> $lines = "" & @CRLF & "Mask=" & $mysubnetmask & @CRLF & "GateWay=" & $mygeteway & @CRLF & "主DNS=" & $mydns & @CRLF & "副DNS=" & $mydns & @CRLF & "" & @CRLF & $lines & ";;CSCDK自己根椐格式复制一下,太多了,不好写。"<br /> If fileexists(@ScriptDir & "\Mac2Ip.ini") Then<br /> $count = MsgBox(8192+256+32+4,"文件已存在","文件" & @ScriptDir & "\Mac2Ip.ini" & "已经存在,是否覆盖?")<br /> If $count = 6 Then<br /> $inifile = fileopen(@ScriptDir & "\Mac2Ip.ini",2)<br /> $x = FileWrite($inifile,$lines)<br /> FileClose($inifile)<br /> If $x Then<br /> GUICtrlSetData($label1,"保存成功")<br /> Else<br /> GUICtrlSetData($label1,"写入失败")<br /> EndIf<br /> EndIf<br /> Else<br /> $inifile = fileopen(@ScriptDir & "\Mac2Ip.ini",2)<br /> $x = FileWrite($inifile,$lines)<br /> FileClose($inifile)<br /> If $x Then<br /> GUICtrlSetData($label1,"保存成功")<br /> Else<br /> GUICtrlSetData($label1,"写入失败")<br /> EndIf<br /> EndIf<br /> EndIf<br />EndFunc ;==>saveas<br />;;;;;;;;;;;;;;;<br />Func getnetworkconfig($tempstr)<br /> for $i = 1 to 4<br /> If $tempstr = $Description[$i] Then<br /> $myipaddress = regread("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $ServiceName[$i] ,"IPAddress")<br /> $mysubnetmask = regread("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $ServiceName[$i] ,"SubnetMask")<br /> $mygeteway = regread("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $ServiceName[$i] ,"DefaultGateway")<br /> $mydns = regread("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $ServiceName[$i] ,"NameServer")<br /> $mydns = StringSplit($mydns,",")<br /> ExitLoop<br /> EndIf<br /> Next<br />EndFunc ;==>getnetworkconfig</p> 居然没人回帖……:face (32):楼主好象没讲清楚做什么用的。 神人啊相当有用滴啊 nbtscan生成列表太慢了啊,纠结
页:
[1]