Ah I like it. Much better than manually grepping for it and I can see some code changes in my scripts already.
On that note though, some slight improvements to the code - it happened to me so I'm passing on the knowledge. Some of it available here: Ancient Perl / Perl 5 Wiki and other bits just my experience in the past. I've cleaned up the sanitation code at the top, cut out the use of variables to help speed things up a little.
In terms of other tools I'm not familiar with any, I usually just grep the nmap OUI file if I need to look one up.
The formatting may have changed slightly (I use different tab stops), but here it is:
Code:
#!/usr/bin/env perl
# MAC address OUI checker
# Thijs (Thice) Bosschert
# http://www.thice.nl
# v0.1 24-06-2010
# Print header
print "\n MAC address OUI checker v0.1\n".
" by Thijs (Thice) Bosschert\n\n";
# Check if argument has been given
if (!$ARGV[0]) {
fatal_error();
}
# Removing seperators from MAC address and uppercase chars
my $OUI = uc($ARGV[0]);
$OUI =~ s/[^0-9A-F]//g;
# Get OUI from MAC
if ($OUI =~ /^[0-9A-F]{6}/) {
print " Checking OUI: ".$OUI."\n";
} else {
fatal_error();
}
# Open OUI file from aircrack-ng
open(my $fh, "<", "/usr/local/etc/aircrack-ng/airodump-ng-oui.txt") || die "Fatal: Can not find airodump file";
while (<$fh>) {
($checkoui,$company) = split(/\(hex\)/,$_);
$checkoui =~ s/[-|\s]//g;
# Check if OUI can be found in the list
if ($OUI eq $checkoui) {
$company =~ s/\t//g;
# Output found OUI
print " Found OUI: ".$OUI." - ".$company."\n\n";
exit;
}
}
close($fh);
# Show if OUI was not found
print " Could not find OUI: ".$OUI."\n\n";
# Error messages
sub fatal_error {
print " Error: No MAC address or OUI specified or could not recognize it.\n".
" Usage: perl $0 <MAC/OUI>\n".
" MAC can be submitted as:\n".
" 001122334455\n".
" 00:11:22:33:44:55\n".
" 00-11-22-33-44-55\n".
" OUI can be submitted as:\n".
" 001122\n".
" 00:11:22\n".
" 00-11-22\n\n";
exit;
}
It is also possible to install it to /bin/ if you wish:
Code:
sudo cp OUI_lookup.pl /bin/OUI_lookup && sudo chmod +x /bin/OUI_lookup
Which means you can just type:
Code:
OUI_lookup 00:11:22:33:44:55
Anyhow good job Hawkje, not a bad first post to these forums.