-
Notifications
You must be signed in to change notification settings - Fork 5
/
oui_lookup.pl
53 lines (41 loc) · 902 Bytes
/
oui_lookup.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
use strict;
# http://standards-oui.ieee.org/oui/oui.txt
my %mac_vendor =();
sub load_mac_vendor_data
{
open(OUI_FILE, "oui.txt") || die "failed to open file";
while (my $line=<OUI_FILE>) {
if ($line =~/^(\w{6})\s+\(base 16\)\s+(\w+.*)$/) {
$mac_vendor{lc($1)} = $2;
}
}
close(OUI_FILE);
}
load_mac_vendor_data();
sub get_mac_vendor
{
my $mac = shift;
$mac = substr($mac, 0, 6);
if (exists $mac_vendor{$mac}) {
return $mac_vendor{$mac};
} else {
return "$mac vendor not found";
}
}
my $mac = shift || '';
my $i = 0;
while ($i++ < 100) {
if (length($mac) < 6) {
print "\n\ninput a mac:";
$mac = <STDIN>;
}
chomp($mac);
$mac =~ s/[:-]//g;
$mac = substr($mac, 0, 6);
$mac = lc($mac);
if (length($mac) == 6) {
print(get_mac_vendor($mac));
}
$mac = '';
}