locked
Script validating a mac address RRS feed

  • Question

  • I need to restrict a single computer access to specific html page.  The client-side script I am looking for will have a section in the code where I can enter a known mac address.  The script will validate the mac address of the machine versus what was manually entered.  If validated, the user can view the page.  If the address can not be validated, redirect the user.  I am trying to do this with absolute minimal input from the user.  None if possible.

    Sunday, April 19, 2009 3:55 AM

Answers

  • Hey Landwire

    Something similar to this should be relatively easy to include in your web pages client side scripting. You will just need to modify it to redirect your users. I'm assuming you would also want to use a compiled server side scripting language rather than embed the MAC address that is permitted to access your web server in the client side script...but this script is just demonstrating how to retrive your clients MAC address and compare it to a given value without any user interaction.

    Hope this helps

    Cheers

    Matt :)

    '----------------------------------------------------------------------------------------------------------------------------
    'Script Name : CompareMACAddresses.vbs
    'Author      : Matthew Beattie
    'Created     : 20/04/09
    'Description : This script demonstrates how to enumerate a systems MAC address and compare it to another.
    '----------------------------------------------------------------------------------------------------------------------------
    'Initialization  Section
    '----------------------------------------------------------------------------------------------------------------------------
    Option Explicit
    Dim objFSO, scriptBaseName, scriptPath
    On Error Resume Next
       Set objFSO        = CreateObject("Scripting.FileSystemObject")
       scriptBaseName    = objFSO.GetBaseName(Wscript.ScriptFullName)
       scriptPath        = objFSO.GetFile(Wscript.ScriptFullName).ParentFolder.Path
       If Err.Number <> 0 Then
          Wscript.Quit
       End If
    On Error Goto 0
    '----------------------------------------------------------------------------------------------------------------------------
    'Main Processing Section
    '----------------------------------------------------------------------------------------------------------------------------
    On Error Resume Next
       ProcessScript
       If Err.Number <> 0 Then
          MsgBox "An unknown error has occurred!", vbCritical, scriptBaseName
       End If
    On Error Goto 0
    '----------------------------------------------------------------------------------------------------------------------------
    'Name       : ProcessScript -> Primary Function that controls all other script processing
    'Parameters : None          -> 
    'Return     : None          -> 
    '----------------------------------------------------------------------------------------------------------------------------
    Function ProcessScript
       Dim ipAddress, macAddress, permittedAddress
       permittedAddress = "0002F3C4C6B4"
       '-------------------------------------------------------------------------------------------------------------------------
       'Enumerate the Systems IP & MAC Address for logging.
       '-------------------------------------------------------------------------------------------------------------------------
       If Not GetIPConfig(ipAddress, macAddress) Then
          Exit Function
       End If
       '-------------------------------------------------------------------------------------------------------------------------
       'Remove any ":" or "-" characters from the MAC address and ensure it is upper case.
       '-------------------------------------------------------------------------------------------------------------------------
       macAddress = UCase(Replace(Replace(macAddress, ":", ""), "-", ""))
       MsgBox "Your systems current MAC address is " & macAddress,   vbInformation, ScriptBaseName
       MsgBox "The system requires MAC address " & permittedAddress, vbInformation, ScriptBaseName
       '-------------------------------------------------------------------------------------------------------------------------
       'Ensure the current systems MAC Address is authorised to access the system
    '------------------------------------------------------------------------------------------------------------------------- If StrComp(macAddress, permittedAddress, vbTextCompare) = 0 Then MsgBox "Your systems MAC address " & macAddress & " is permitted access.", vbInformation, ScriptBaseName Else MsgBox "Your systems MAC address " & macAddress & " is Denied access.", vbCritical, ScriptBaseName End If End Function '---------------------------------------------------------------------------------------------------------------------------- 'Name : GetIPConfig -> Enumerates the IP & MAC Address of the system via WMI 'Parameters : ipAddress -> Input/Output : Variable assigned to the IP Address of the system. ' : macAddress -> Input/Output : Variable assigned to the MAC Address of the system. 'Return : GetIPConfig -> Returns True and the systems IP & MAC Address if successful otherwise returns False. '---------------------------------------------------------------------------------------------------------------------------- Function GetIPConfig(ipAddress, macAddress) Dim objConfig GetIPConfig = False ipAddress = "" On Error Resume Next For Each objConfig in Getobject("winmgmts:").ExecQuery("select * from " & _ "Win32_NetworkAdapterConfiguration where IPEnabled = True") ipAddress = objConfig.IPAddress(0) macAddress = objConfig.MACAddress(0) If ipAddress <> "" And ipAddress <> "0.0.0.0" And MACAddress <> "" Then Exit For End If Next On Error Goto 0 If Err.Number <> 0 Then Exit Function End If GetIPConfig = True End Function '----------------------------------------------------------------------------------------------------------------------------

    • Proposed as answer by MatthewBeattie Monday, April 20, 2009 12:58 PM
    • Marked as answer by IamMred Friday, January 8, 2010 12:03 AM
    Monday, April 20, 2009 12:57 PM