book1.xls内,A列为网段内IP,192.168.1.1 ....... 192.168.1.255
扫描到的MAC保存在B列。
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <Excel.au3>
#include <Sound.au3>
$oExcel = _ExcelBookOpen("d:\book1.xls")
If @error = 1 Then
MsgBox(0, "Error!", "Unable to Create the Excel Object")
Exit
ElseIf @error = 2 Then
MsgBox(0, "Error!", "File does not exist - Shame on you!")
Exit
EndIf
$TheFrist1 = 1
While 1
$sIP = _ExcelReadCell($oExcel, $TheFrist1, 1)
If $sIP <> "" Then
$TheFrist1 = $TheFrist1 + 1
Else
$TheEnd1 = $TheFrist1 - 1
$TheFrist1 = 1
ExitLoop
EndIf
WEnd
GUICreate("IP To MAC", 360, 430, 0, 0)
$ListView1 = GUICtrlCreateEdit("", 0, 0, 350, 390)
$Font = "Verdana"
GUICtrlSetFont(-1, 10, 800, 0, $Font)
$Button1 = GUICtrlCreateButton("开始", 95, 400, 75, 25, 0)
$Button2 = GUICtrlCreateButton("退出", 190, 400, 75, 25, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_ExcelBookSaveAs($oExcel, "D:\book1.xls", "xls", 0, 1)
_ExcelBookClose($oExcel, 1)
Exit
Case $Button1
IPMAC()
Case $Button2
_ExcelBookSaveAs($oExcel, "D:\book1.xls", "xls", 0, 1)
_ExcelBookClose($oExcel, 1)
Exit
EndSwitch
WEnd
Func IPMAC()
For $Strat = $TheFrist1 To $TheEnd1
$sIP = _ExcelReadCell($oExcel, $strat, 1)
$MAC = _GetMAC($sIP)
If $MAC <> "00:00:00:00:00:00" Then
$OldMAC=_ExcelReadCell($oExcel, $strat, 2)
If $OldMAC<>"" And $OldMAC<>$MAC Then
_ExcelWriteCell($oExcel, $MAC, $strat, 3)
Else
_ExcelWriteCell($oExcel, $MAC, $strat, 2)
EndIf
Addlog($sIP & " -> " & $MAC)
Else
Addlog($sIP)
EndIf
Next
EndFunc ;==>Timer
Func Addlog($lcStr)
GUICtrlSetData($ListView1, GUICtrlRead($ListView1) & @CRLF & $lcStr)
GUICtrlSetData($ListView1, " ", True)
EndFunc ;==>Addlog
Func _GetMAC($sIP)
Local $MAC, $MACSize
Local $i, $s, $r, $iIP
$MAC = DllStructCreate("byte[6]")
$MACSize = DllStructCreate("int")
DllStructSetData($MACSize, 1, 6)
$r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
$iIP = $r[0]
$r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
$s = ""
For $i = 0 To 5
If $i Then $s = $s & ":"
$s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
Next
Return $s
EndFunc ;==>_GetMAC |