Скрипт для определения производителя оборудования по MAC-адресу

Данный скрипт может быть полезен для идентификации сетевого оборудования, которое вызывает те или иные проблемы в сети. Этот скрипт помог мне устранить дублирование IP-адресов в сети клиента, когда один из ADSL модемов и компьютер имели одинаковые IP-адреса.

Для работы скрипт использует базы IEEE Registration Authority: Individual Address Block (IAB) и Organizationally Unique Identifiers (OUI). Базы IAB и OUI обновляются регулярно, поэтому перед поиском, рекомендую обновить их запустив скрипт с параметром /u. Для поиска выполните скрипт с параметром /m:<MAC-адрес>

Ниже приведен сам скрипт mac2vendor.vbs:

'*******************************************************************************
'* File: mac2vendor.vbs
'* Purpose: Finds Vendor information for particular MAC address
'* Usage: MAC2VENDOR.VBS /m:MAC_ADDR [/u] '* Version: 1.2
'*
'* Technology: VBSCRIPT,WSH
'* Requirements: Windows 2000
'*
'* Authors: Alexander Suhovey
'*
'* History: 1.2 - Fixed performance problem when searching IAB
'* 1.1 - Added EOF check
'*
'*******************************************************************************
Option Explicit
'On Error Resume Next'********************
'* Define Constants
'********************
'* Script version
Const S_VER="1.2"
'* RegExp pattern for valid MAC address
Const MAC_PATTERN = "^([0-9A-F][0-9A-F]-){5}([0-9A-F][0-9A-F])$"
'* RegExp pattern for valid OUI
Const OUI_PATTERN = "^([0-9A-F][0-9A-F]-){2}([0-9A-F][0-9A-F])$"
'* MAC to Vendor mapping files
Const OUI_URL = "http://standards.ieee.org/regauth/oui/oui.txt"
Const IAB_URL = "http://standards.ieee.org/regauth/oui/iab.txt"
'*Local file names for mapping files
Const OUI_FILE = "mac2vendor-oui.txt"
Const IAB_FILE = "mac2vendor-iab.txt"
'* OUI owned by IEEE Registration Authority
Const IAB_OUI = "00-50-C2"'********************
'* Declare variables
'********************
Dim i,sCmd,oShell,oArg,sMAC,sMACl,sMACr,bU,sPath,oFso,oHTTP
Dim iStatus,oFile,sLine,sLinep'****************************************
'Check if script is running by cscript.
'If not, restart script using cscript.
'****************************************
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
sCmd = "cmd /k cscript.exe /nologo """ & WScript.ScriptFullName & """"
Set oArg = WScript.Arguments
For i = 0 To oArg.Count - 1
sCmd = sCmd & " " & oArg(i)
Next
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run sCmd, 1, False
WScript.Quit
End If

'********************
'* Parse arguments
'********************
WScript.Echo
bU=False
Set oArg = WScript.Arguments.Named
Set oFso = CreateObject("Scripting.FileSystemObject")
sPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName)-Len(WScript.ScriptName))
sMAC = Replace(UCase(oArg("m")),":","-")
If oArg.Count<1 or (oArg("m")="" and not oArg.Exists("u")) Then
Syntax()
WScript.Quit 1
End If

If sMAC<>"" and (not ArgVrf(sMAC,MAC_PATTERN)) Then
If not ArgVrf(sMAC,OUI_PATTERN) Then
WScript.Echo "ERROR: Invalid MAC address - '" & oArg("m") & "'" & VbCrLf
Syntax()
WScript.Quit 1
Else
If sMAC=IAB_OUI Then
WScript.Echo IAB_OUI & " is a special OUI used by IEEE Registration Authority " & VbCrLf &_
"to assign IABs to smaller Vendors who does not qualify for OUI. " & VbCrLf &_
"Enter full MAC address to find a Vendor." & VbCrLf & VbCrLf
WScript.Quit
End If
End If
End If

If oArg.Exists("u") Then
bU = True
Else
If (not oFso.FileExists(sPath & OUI_FILE)) or (not oFso.FileExists(sPath & IAB_FILE)) Then
WScript.Stdout.Write "ERROR: Cannot find MAC to Vendor mapping file(s) in '"&sPath&"'"&VbCrLf&_
" Would you like to download them(~1.6MB) from IEEE Web Site?[Y/N]"
sLine = WScript.StdIn.ReadLine
WScript.Echo
If UCase(sLine) = "Y" Then
bU = True
Else
WScript.Quit
End If
End If
End If

'********************
'* Main section
'********************
'* Update mapping files
If bU Then
Download OUI_URL,sPath,OUI_FILE
Download IAB_URL,sPath,IAB_FILE
WScript.Echo
End If

'*Search for MAC
If sMAC<>"" Then
sMACl = Left(sMAC,8)
sMACr = Replace(Right(sMAC,8),"-","")
If sMACl=IAB_OUI Then
Set oFile = oFso.OpenTextFile(sPath & IAB_FILE, 1)
Do Until oFile.AtEndOfStream
sLine =oFile.ReadLine
If Left(sLinep,8)=IAB_OUI Then
If sMACr<=Mid(sLine,8,6) Then
If Left(sLine,6)<=sMACr Then
WScript.Echo sLinep
WScript.Echo sLine
Do Until sLine="" or oFile.AtEndOfStream
sLine =oFile.ReadLine
WScript.Echo sLine
Loop
WScript.Quit
End If
End If
End If
sLinep = sLine
Loop
Else
Set oFile = oFso.OpenTextFile(sPath & OUI_FILE, 1)
Do Until oFile.AtEndOfStream
sLine =oFile.ReadLine
If Left(sLine,8)=sMACl Then
WScript.Echo sLine
Do Until sLine="" or oFile.AtEndOfStream
sLine =oFile.ReadLine
WScript.Echo sLine
Loop
WScript.Quit
End If
Loop
End If
Wscript.Echo sMAC & " not found." & VbCrLf &_
"Either it is not assigned or you have old mapping files." & VbCrLf &_
"To download most recent mapping files from IEEE Web Site," & VbCrLf &_
"run this script with '/u' key." & VbCrLf
End If

'********************
'* Subroutines
'********************
'* Syntax
Sub Syntax()
Dim s
s = "MAC2VENDOR.VBS v" & S_VER & VbCrLf
s = s & "Finds Vendor information for particular MAC address. " & VbCrLf & VbCrLf
s = s & "SYNTAX: MAC2VENDOR.VBS /m:MAC_ADDR [/u]" & VbCrLf & VbCrLf
s = s & " /m:MAC_ADDR : MAC address to search for. Dashes, colons, upper or"&VbCrLf
s = s & " lower case letters allowed. Can be full MAC or first"&VbCrLf
s = s & " three octets(OUI)."& VbCrLf
s = s & " /u : Download or update mapping files. IEEE Registration "&VbCrLf
s = s & " Authority maintains a database of assigned MAC address"&VbCrLf
s = s & " ranges. It is available for download at following URLs:"&VbCrLf
s = s & " " & OUI_URL & VbCrLf
s = s & " " & IAB_URL & VbCrLf & VbCrLf
s = s & "EXAMPLES:" & VbCrLf & VbCrLf
s = s & " MAC2VENDOR.VBS /m:"&IAB_OUI&"-67-89-0a" & VbCrLf
s = s & " MAC2VENDOR.VBS /m:00:00:0C" & VbCrLf
s = s & " MAC2VENDOR.VBS /u" & VbCrLf & VbCrLf
s = s & "LINKS:" & VbCrLf & VbCrLf
s = s & " IEEE Registration Authority FAQ:" & VbCrLf
s = s & " http://standards.ieee.org/faqs/OUI.html" & VbCrLf & VbCrLf
s = s & " Current OUI and IAB databases:"& VbCrLf
s = s & " " & OUI_URL & VbCrLf & " " & IAB_URL & VbCrLf
WScript.Echo s
End Sub

'* Regexp validation
Function ArgVrf(sArg,sPattern)
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.IgnoreCase = False
objRegExp.Pattern = sPattern
ArgVrf = objRegExp.Test(sArg)
Set objRegExp = Nothing
End Function

'* Download mapping files
Sub Download(sURL,sP,sOut)
Dim b
WScript.Stdout.Write "Downloading "&sOut&" file..."
Set oHTTP = CreateObject("Microsoft.XMLHTTP")
On Error Resume Next
oHTTP.Open "GET",sURL,False
oHTTP.Send
b = oHTTP.responseBody
If Err.Number <> 0 Or oHTTP.Status <> 200 Then
Err.Clear
WScript.Echo " Failed!"&VbCrLf&"ERROR: Cannot download file from "&sURL&VbCrLf
WScript.Quit 1
End If
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write b
.SaveToFile sP&sOut,2
If Err.Number <> 0 Then
Err.Clear
WScript.Echo " Failed!"&VbCrLf&"ERROR: Cannot save file to '"&sOut&"'"&VbCrLf
WScript.Quit 1
End If
End With
WScript.Echo " Done."
On Error GoTo 0
End Sub

'********************
'* End of script
'********************

Скачать mac2vendor.zip

Пожалуйста, оцените статью:
(всего оценок: 5, средняя: 4,80 из 5)