use 5.010; use strict; use warnings; # filehandle section open STDOUT, ">ouiresults.txt"; # Output file after program is run. open STDERR, ">errlog.txt"; # Error Log. my $f1 = 'oui.txt'; # Filehandle of the OUI list from the IETF used to create a hash of oui and company. my @data = (); # Declared Array to be created with the input file for searching the MAC address. my %hash = (); # Declared Hash to be created with the input file to store the IP to MAC mappings. my %oui = (); # Delcared Hash containing the OUI to Company mapping. open (LIST1, $f1) || die "File not found\n"; # Takes the oui file and creates a hash while () { # Key is OUI chomp; # Value is Company if (/[\x20]{5}\(base 16\)[\t]{2}/) { $oui{$`} = $'; } } close LIST1; open(INPUT, $ARGV[0]) || die "Cannot do eet! $!"; # Takes the input file name on the command line and builds an array. while () { # This is the ARP Cache file created from a copy/paste of a routers push @data, "$_"; # show arp command. } close(INPUT); for (@data) { # This section iterates over the ARP cache array and pulls the IP and MAC address out and stores it into a hash if ($_ =~ m/([\d]+\.[\d]+\.[\d]+\.[\d]+).*([\w]{4})\.([\w]{4})\.([\w]{4})/i) { # Key is MAC my $temp = $2.$3.$4; # Value is IP $hash{$temp} = $1; } } while ( my ( $key, $value ) = each %hash ) { my $match = substr $key, 0, 6; say "$hash{$key} mapped to $key for company $oui{$match}!"; }