Skip to content

Verify MAC Harware vendors against OUI #4

@jsarcand

Description

@jsarcand

Hi, In order to determine subsets of vendors connecting to Lyrion - directly or through plugins - it would be interesting to validate the vendors against the MAC address of the endpoints.

1- A OUI file can be bundled from the IEEE website
2- The following code should work (Replace 'path/to/oui.txt' with the actual path to the OUI file)

use strict;
use warnings;

#Function to get manufacturer from MAC address
sub get_manufacturer {
    my ($mac) = @_;
    
    # Normalize MAC address
    $mac =~ s/[:-]//g;  # Remove colons or dashes
    my $oui = substr($mac, 0, 6);  # Get the first 6 characters (OUI)

    # Open the OUI file
    open my $fh, '<', 'path/to/oui.txt' or die "Could not open OUI file: $!";
    
    while (my $line = <$fh>) {
        if ($line =~ /^\s*($oui)\s+/) {
            close $fh;
            return $line;  # Return the line containing the manufacturer
        }
    }
    
    close $fh;
    return "Manufacturer not found";
}

# Example MAC address
my $mac_address = '00:1A:2B:3C:4D:5E';
my $manufacturer = get_manufacturer($mac_address);
print "Manufacturer: $manufacturer\n";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions