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 %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 a hash. while () { # This is the ARP Cache file created from a copy/paste of a Cisco routers arp cache if ($_ =~ m/(\d+\.\d+\.\d+\.\d+).*(\w{4})\.(\w{4})\.(\w{4})/) { # Key is MAC my $temp = $2.$3.$4; # Value is IP $hash{$temp} = $1; } } close(INPUT); while ( my ( $key, $value ) = each %hash ) { my $match = substr $key, 0, 6; say "$hash{$key} mapped to $key for company $oui{$match}!"; }