|
借鉴了别人的代码.
现在问题 扫描时窗口反应慢.
然后最主要的是扫的IP,有些电脑名显不出来
应该是Inet.au3 里面的_TCPIpToName()的问题.
但本人太差.不知道有没有别的更准确的方法??#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\..\资料\做好的logo\未命名.ico
#AutoIt3Wrapper_outfile=G:\开机启动\setip\scanip.exe
#AutoIt3Wrapper_Res_Description=扫描IP,MAC,电脑名
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=TY
#AutoIt3Wrapper_Res_Field=功能|扫描IP,MAC,电脑名
#AutoIt3Wrapper_Res_Field=QQ|362699512
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ACN_NET.au3>
#include <iNet.au3>
#include <GUIConstantsEx.au3>
#include <Guiipaddress.au3>
#include <GuiListView.au3>
Dim $startip ,$endip
Dim $Group1
$startip=StringSplit(@IPAddress1,".",2)
If $startip[0] = 192 Then
$startip = $startip[0]&"."&$startip[1]&"."&$startip[2]&"."
EndIf
$Form1 = GUICreate("扫描 MAC 地址 --TY ", 400, 318)
$Button1 = GUICtrlCreateButton("扫描 MAC", 315, 220, 78, 25)
$Button2 = GUICtrlCreateButton("设置IP地址", 315, 12, 78, 25)
$Button5 = GUICtrlCreateButton("退出", 315, 265, 78, 25)
$listview=GUICtrlCreateListView("电脑名| ip | arp ",8,10,300,200)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
;GUICtrlSetState($listview, $GUI_FOCUS)
$Group1 = GUICtrlCreateGroup("扫描MAC地址 ( 192.168.开始 ) ", 5, 220, 300, 70)
GUICtrlCreateLabel("开始IP地址 结束IP地址 ",10,240)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 10, 255, 130, 25)
_GUICtrlIpAddress_Set($IPAddress1, $startip&1)
_GUICtrlIpAddress_SetRange ($IPAddress1, 0, 192,192)
_GUICtrlIpAddress_SetRange ($IPAddress1, 1, 168,168)
GUICtrlCreateLabel(" 到 ",142,260)
$IPAddress2 = _GUICtrlIpAddress_Create($Form1, 170, 255, 130, 25)
_GUICtrlIpAddress_Set($IPAddress2, $startip&254)
_GUICtrlIpAddress_SetRange ($IPAddress2, 0, 192,192)
_GUICtrlIpAddress_SetRange ($IPAddress2, 1, 168,168)
$label1 = GUICtrlCreateLabel("",5,296,388,22,0x01,0x00000200 +0x00100000)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 10, 500, 0, "Comic Sans MS")
GUISetState(@SW_SHOW)
If FileExists("ipmac.ini") Then
$temp = IniReadSection( "ipmac.ini", "ipmac")
If (@error<>1 And $temp[0][0]>0) Then
For $i = 1 To $temp[0][0]
$temp2=StringSplit($temp[$i][1],"|",2)
GUICtrlCreateListViewItem($temp2[1]&"|"&$temp2[0]&"|"&$temp[$i][0],$listview)
Next
GUICtrlSetData($label1 , "配置文件中共有 : "&$temp[0][0]&"个数据")
EndIf
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ;扫描IP 2 ARP
GUICtrlSetState($Button1,$GUI_DISABLE)
GUICtrlSetState($Button2,$GUI_DISABLE)
GUICtrlSetState($Button5,$GUI_DISABLE)
$startip = _GUICtrlIpAddress_Get($IPAddress1)
$endip = _GUICtrlIpAddress_Get($IPAddress2)
GUICtrlDelete($listview) ;重建列表控件
$listview=GUICtrlCreateListView("电脑名| ip | arp ",8,10,300,200)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
;GUICtrlSetState($listview, $GUI_FOCUS)
TCPStartup()
Scanip2arp($startip,$endip)
TCPShutdown()
GUICtrlSetState($Button1,$GUI_ENABLE)
GUICtrlSetState($Button2,$GUI_ENABLE)
GUICtrlSetState($Button5,$GUI_ENABLE)
Case $Button2
If Run("setip.exe")=0 Then
GUICtrlSetState($Button2,$GUI_DISABLE)
ToolTip("作者:362699512"&@CRLF&"功能: 扫描 MAC 地址,IP,电脑",@DesktopWidth-300,@DesktopHeight-100,"缺少setip.exe,请检查是否放在同一目录下",3)
Sleep(3000)
GUICtrlSetState($Button2,$GUI_ENABLE)
ToolTip("")
EndIf
Case $Button5
Exit
EndSwitch
WEnd
Func Scanip2arp($startip,$endip) ;扫描IP 2 ARP ----------过程
$startip = StringSplit($startip,".",2)
$endip = StringSplit($endip,".",2)
Local $i ,$j ,$o ,$p ,$t=0,$m=0
If $startip[2] = $endip[2] Then ;当起始IP和结束IP 192.168.x 中的X都相同时
If $startip[3] <= $endip[3] Then
For $i = $startip[3] To $endip[3]
GUICtrlSetData($label1 , "状态 : "&"正在扫描 "&"192.168."&$startip[2]&"."&$i)
If Ping("192.168."&$startip[2]&"."&$i, 5)=0 Then ContinueLoop
If GUIGetMsg()=$GUI_EVENT_CLOSE Then ExitLoop
$m += ip2arp("192.168."&$startip[2]&"."&$i)
Next
GUICtrlSetData($label1 , "完成 : 共扫描 "&$endip[3]-$startip[3]+1&" 个IP ,共扫到 "&$m&" 个Mac地址")
Else
ToolTip("作者:362699512"&@CRLF&"功能: 扫描 MAC 地址,IP,电脑",@DesktopWidth-230,@DesktopHeight-100,"开始IP地址 大于 结束IP地址",3)
Sleep(3000)
ToolTip("")
EndIf
Else ;当起始IP和结束IP 192.168.x 中的X都不相同时
If $startip[2] < $endip[2] Then
For $i=$startip[2] To $endip[2]
If $i<$endip[2] Then ;正在扫描中的IP 192.168.x 中的x 小于结束IP中的X时,扫到254
$o = 254
Else
$o = $endip[3]
EndIf
If $i > $startip[2] Then ;正在扫描中的IP 192.168.x.y中的x 等于开始IP中的X时,从开始IP的Y开始扫,如果大于开始IP中的X时,从0开始扫
$p = 0
Else
$p = $startip[3]
EndIf
$t=$t+$o-$p+1
For $j = $p To $o
GUICtrlSetData($label1 , "状态 : "&"正在扫描 "&"192.168."&$i&"."&$j)
If Ping("192.168."&$i&"."&$j, 5)=0 Then ContinueLoop
If GUIGetMsg()=$GUI_EVENT_CLOSE Then ExitLoop
$m += ip2arp("192.168."&$i&"."&$j)
Next
Next
GUICtrlSetData($label1 , "完成 : 共扫描 "&$t& " 个IP ,共扫到 "&$m&" 个Mac地址")
Else
ToolTip("作者:362699512"&@CRLF&"功能: 扫描 MAC 地址,IP,电脑",@DesktopWidth-230,@DesktopHeight-100,"开始IP地址 大于 结束IP地址",3)
Sleep(3000)
ToolTip("")
EndIf
EndIf
EndFunc
Func ip2arp($ip) ;调用 <ACN_NET.au3> 中的_API_Get_NetworkAdapterMAC ($IP) 函数 IP得到 ARP
Local $name ,$i=0,$arp = _API_Get_NetworkAdapterMAC ($IP)
If $arp <> "00:00:00:00:00:00" Then
$name = _TCPIpToName($ip)
GUICtrlCreateListViewItem($name&"|"&$ip&"|"&StringReplace ($arp,":","-"),$listview)
$i=$i+1
If ($name<>""And $ip<>"" And $arp<> "") Then
IniWrite ( "ipmac.ini", "ipmac", StringReplace ($arp,":","-"), $ip&"|"&$name)
EndIf
EndIf
Return $i
EndFunc
改IP的源码
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\..\资料\做好的logo\未命名.ico
#AutoIt3Wrapper_outfile=G:\开机启动\setip\setip.exe
#AutoIt3Wrapper_Res_Description=根据本机MAC地址,设置电脑名,IP,IPX网络号
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=TY
#AutoIt3Wrapper_Res_Field=功能|根据本机MAC地址,设置电脑名,IP,IPX网络号
#AutoIt3Wrapper_Res_Field=QQ|362699512
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
If FileExists("ipmac.ini")=0 Then
MsgBox(16,"提示","没有发现设置文件.请手动设置参数",3)
_set_byhand()
Else
$mask=IniRead ( "ipmac.ini", "set", "mask", "0")
$Gateway=IniRead ( "ipmac.ini", "set", "Gateway", "0")
$dns1=IniRead ( "ipmac.ini", "set", "dns1", "0")
$dns2=IniRead ( "ipmac.ini", "set", "dns2", "0")
$mac=StringReplace (_GetLocalMAC(),":","-") ;调用_GetlocalMAC() 得到本机mac
If $mac = "0" Then
MsgBox(16,"没有找到本机MAC地址,请检查.(5秒后退出!)","本程序只设置 :连接上网线并且状态是启用的网卡"&@CRLF&@CRLF&"网线是否连接?"&@CRLF&"连接网线的网卡是否被禁用",5)
Exit
EndIf
$pc_ip=IniRead ( "ipmac.ini", "ipmac", $mac, "0") ;读取ipmac.ini中有没有本机mac设置
If $pc_ip="0" Then
MsgBox(16,"提示","在配置文件中没有发现本机mac地址 : "&$mac&" ,请手动设置IP",3)
_set_byhand()
Else
$pc_ip=StringSplit($pc_ip,"|",2)
ToolTip(" 在设置文件中找到对应设置"&@CRLF&"电脑名 :"&$pc_ip[1]&@CRLF&"IP :"&$pc_ip[0],@DesktopWidth-260,@DesktopHeight-110,"本机MAC地址 :"&$mac,1)
Sleep(3000)
_SetComputerName($pc_ip[1])
_SetIPAddress($pc_ip[0],$Mask, $Gateway,$dns1,$dns2)
ToolTip("作者:362699512"&@CRLF&"功能: 根据mac地址设置IP,电脑,IPX网络号",@DesktopWidth-255,@DesktopHeight-95,"全部设置,结束! 3秒后退出.",1)
Sleep(3000)
EndIf
EndIf
Func _set_byhand()
$Form1 = GUICreate("请输入参数", 265, 300, 442, 277)
GUISetIcon("E:\资料\做好的logo\未命名.ico", -1)
$Label1 = GUICtrlCreateLabel("电脑名 :", 17, 19, 65, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("IP 地址 :", 17, 63, 70, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("子网掩码:", 17, 104, 77, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("网 关 :", 17, 144, 58, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("主DNS :", 17, 184, 68, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("备用DNS :", 17, 224, 85, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("001a", 112, 16, 129, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("192.168.0.1", 112, 57, 129, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("255.255.255.0", 112, 98, 129, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input4 = GUICtrlCreateInput("192.168.0.254", 112, 138, 129, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input5 = GUICtrlCreateInput("202.96.128.86", 112, 179, 129, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input6 = GUICtrlCreateInput("61.144.56.100", 112, 219, 129, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("设置", 24, 256, 100, 33)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("退出", 140, 256, 100, 33)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $Button1
$pcname=GUICtrlRead($Input1)
$ip=GUICtrlRead($Input2)
$Mask=GUICtrlRead($Input3)
$Gateway=GUICtrlRead($Input4)
$dns1=GUICtrlRead($Input5)
$dns2=GUICtrlRead($Input6)
GUIDelete($Form1)
_SetComputerName($pcname)
_SetIPAddress($ip,$Mask, $Gateway,$dns1,$dns2)
ToolTip("全部设置,结束! 3秒后退出.",@DesktopWidth-170,@DesktopHeight-80,"提示",1)
Sleep(3000)
Exit
Case $msg = $Button2
Exit
EndSelect
WEnd
EndFunc
Func _GetLocalMAC() ;得到本机 ARP
$mac="0"
Dim $aNULL[1] = [0]
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
;$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
;Win32_NetworkAdapter Where NetConnectionStatus =2 状态为联接
$colNicConfigs = $objWMIService.ExecQuery ("Select * FROM Win32_NetworkAdapter Where NetConnectionStatus =2", "WQL", 0x30)
If IsObj($colNicConfigs) Then
For $objItem In $colNicConfigs
$objNic = $objWMIService.Get ("Win32_NetworkAdapter.DeviceID=" & $objItem.Index)
$MAC =$objNic.MACAddress
Next
Return $mac
EndIf
EndFunc ;_GetLocalMAC获取本地MAC地址
Func _SetIPAddress($ip, $Mask, $Gateway,$dns1,$dns2) ;设置本机IP , IPX网络号
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
;得到当前活动网卡ID
$colItems = $objWMIService.ExecQuery("Select * from Win32_TSNetworkAdapterListSetting")
For $Item In $colItems
$AdapterID = $Item.NetworkAdapterID
Next
ToolTip("正在设置IP:"&$ip&",请稍等...",@DesktopWidth-240,@DesktopHeight-80,"提示",1)
;通过注册表修改DNS IP
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\" & $AdapterID, "IPAddress", "REG_MULTI_SZ", $ip)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\" & $AdapterID, "SubnetMask", "REG_MULTI_SZ", $mask)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\" & $AdapterID, "DefaultGateway", "REG_MULTI_SZ", $Gateway)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\" & $AdapterID, "NameServer", "REG_SZ", $dns1&","&$dns2)
$ip=StringSplit($ip,".",2);改IPX 网络号
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NwlnkIpx\Parameters", "VirtualNetworkNumber", "REG_DWORD", "0x"&$ip[2]&$ip[3]);IPX协议号
;通过Ipconfig命令,重新注册DNS。目的让它立即生效
Run(@ComSpec & " /c ipconfig /registerdns", "", @SW_HIDE)
Sleep(1000)
EndFunc ;_SetIPAddress修改IP地址
Func _SetComputerName($strComputerName) ;设置本机电脑名
ToolTip("正在设置电脑名:"&$strComputerName&",请稍等...",@DesktopWidth-210,@DesktopHeight-80,"提示",1)
RegWrite ( "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $strComputerName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $strComputerName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $strComputerName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $strComputerName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $strComputerName)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $strComputerName)
Sleep(1000)
EndFunc ;_SetComputerName修改计算机名
Func _setcdkey()
;RegWrite ("HKEY_CURRENT_USER\Software\Valve\CounterStrike\Settings\","KEY","REG_SZ",$CD)
;RegWrite ("HKEY_CURRENT_USER\Software\Valve\HALF-LIFE\Settings\","KEY","REG_SZ",$CD)
EndFunc |
|