Как-то случайно натыкался на полезные скрипты для определения по мак адресу айпи компьютера:
такой вот коротенький батничек, пингующий группу адресов и записывающий в файлик arp_table.txt
@echo off if exist arp_table.txt ( if exist arp_table.bak del arp_table.bak ren arp_table.txt arp_table.bak ) for /L %%i in (1,1,254) do ( echo 192.168.0.%%i ping -n 1 192.168.0.%%i>nul arp -a 192.168.0.%%i>arp_string.tmp for /F "skip=3 tokens=*" %%j in (arp_string.tmp) do ( echo %%j|find /V "invalid">>arp_table.txt ) ) del arp_string.tmp
и более тотальный скрипт:
'******************************************************************************
'* File: mac2ip.vbs
'* Purpose: Finds IP of the host with given MAC address.
'* Syntax: cscript mac2ip.vbs /mac:MAC_ADDRESS /ip:IP_BLOCK [/p:pause]
'* Version: 1.0.2
'*
'* Technology: VBSCRIPT,WSH,WMI
'* Requirements: Windows XP or newer (uses Win32_PingStatus WMI class)
'*
'* Authors: 4u3u (asuhovey mtu-net ru)
'*
'******************************************************************************
Option Explicit
'On Error Resume Next
Dim objShell,strOutput,i,strMAC,objOutput,objAdapter,intPause
Dim strSTime,strIP,strNameSpace,strQuery,colAdapters,PausePattern
Dim colResult,IPPattern,MACPattern,strArpCommand,strOMAC
'* Matches valid MAC address
MACPattern = "^([0-9a-f][0-9a-f]-){5}([0-9a-f][0-9a-f])$"
'*Matches valid IP block
IPPattern = "^b((25[0-5]|2[0-4]d|[01]dd|d?d).){3}$"
'*Matches positive integer
PausePattern = "^d+$"
'****************************************
'Parse arguments
'****************************************
strOMAC = WScript.Arguments.Named("mac")
strMAC = Replace(LCase(strOMAC),":","-")
strIP = Wscript.Arguments.Named("ip")
intPause = Wscript.Arguments.Named("p")
If intPause="" Then intPause=1000
If Wscript.Arguments.Count<2 Then
Syntax()
End If
If not ArgVrf(strMAC,MACPattern) Then
WScript.Echo "ERROR: Invalid MAC: '" & strOMAC & "' Check syntax..." & VbCrLf
Syntax()
End If
If not ArgVrf(strIP,IPPattern) Then
WScript.Echo "ERROR: Invalid IP: '" & strIP & "' Check syntax..." & VbCrLf
Syntax()
End If
If not ArgVrf(intPause,PausePattern) Then
WScript.Echo "ERROR: Invalid Pause: '" & intPause & "' Must be positive integer." & VbCrLf
Syntax()
End If
''****************************************
'Check if script is running by cscript.
'If not, restart script using cscript.
'****************************************
Set objShell = WScript.CreateObject("WScript.Shell")
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
objShell.Run "cmd /k cscript.exe /nologo """ & WScript.ScriptFullName & """ /mac:" &_
strOMAC & " /ip:" & strIP & " /p:" & intPause, 1, False
WScript.Quit
End If
'****************************************
'Check if given MAC is owned by local host
'****************************************
strNameSpace = "winmgmts:{impersonationLevel=impersonate}//./root/cimv2"
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"
Set colAdapters = GetObject(strNameSpace). ExecQuery(strQuery)
For Each objAdapter in colAdapters
If LCase(Replace(objAdapter.MACAddress,":","-")) = strMAC Then
WScript.Echo strOMAC & " is YOUR MAC address!"
WScript.Quit
End If
Next
'****************************************
'Ping all IPs in range.
'****************************************
strSTime = Now()
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & strIP
For i = 1 To 254 Step 1
Set colResult = GetObject(strNameSpace). ExecQuery(strQuery & i & "'")
WScript.StdOut.Write "."
If i/51-Int(i/51)=0 Then
WScript.StdOut.WriteLine " " & Int(100*i/254) & "%"
End If
Next
WScript.Echo ". 100%" & VbCrLf & "Ping completed in " & DateDiff("s",strSTime,Now()) & " seconds." & VbCrLf
'****************************************
'Get IP-MAC pair from ARP cache.
'****************************************
WScript.Sleep(intPause)
strArpCommand = "%comspec% /c arp.exe -a | find /i """ & strMAC & """"
Set objOutput=objShell.Exec(strArpCommand).StdOut
WScript.Echo String(56,"=")
i=0
Do While Not objOutput.AtEndOfStream
i=i+1
strOutput = objOutput.ReadLine
WScript.Echo StrOMAC & " is " & RTrim(Left(LTrim(strOutput),15))
Loop
If i=0 Then
WScript.Echo strOMAC & " was NOT FOUND" &_
" on the local network" & VbCrLf &_
"Either host is unreachable or " & strIP &_
"xxx is not" & VbCrLf & "your local network."
End If
WScript.Echo String(56,"=")
'****************************************
'Subroutines
'****************************************
'*Syntax
Sub Syntax()
Dim s
s = "Finds IP of the host with given MAC address." & VbCrLf & VbCrLf
s = s & "SYNTAX: cscript /nologo " & UCase(WScript.ScriptName) &_
" /mac:MAC_ADDRESS /ip:IP_BLOCK [/p:pause]" & VbCrLf & VbCrLf
s = s & " MAC_ADDRESS MAC address to search for. MAC_ADDRESS" & VbCrLf
s = s & " is in XX-XX-XX-XX-XX-XX format. Both" & VbCrLf
s = s & " ':' and '-' delimiters allowed." & VbCrLf
s = s & " IP_BLOCK First three octets of local ip range to" & VbCrLf
s = s & " scan. E.g. '192.168.0.' Only /24 subnets" & VbCrLf
s = s & " are supported in current version." & VbCrLf
s = s & " pause Pause after ping in milliseconds." & _
VbCrLf & " Default is 1000 (1 second)" & VbCrLf & VbCrLf
s = s & "Example:" & VbCrLf
s = s & " cscript /nologo " & UCase(WScript.ScriptName) &_
" /mac:01-23-45-67-89-AB /ip:192.168.0." & VbCrLf
WScript.Echo s
WScript.Quit 1
End Sub
'*Arguments validation
Function ArgVrf(arg,pattern)
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.IgnoreCase = true
objRegExp.Pattern = pattern
ArgVrf = objRegExp.Test(arg)
Set objRegExp = Nothing
End Function
'****************************************
'End of script
'****************************************