-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathname2mac.pm
More file actions
56 lines (44 loc) · 1.22 KB
/
name2mac.pm
File metadata and controls
56 lines (44 loc) · 1.22 KB
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
54
55
56
package name2mac;
use warnings;
use strict;
use autodie;
use Data::Dump qw(dump);
my $debug = 1;
my @name_mac_files = ( qw( /dev/shm/sw-name-mac /dev/shm/wap-name-mac ), $ENV{NAME_MAC}, glob '/dev/shm/name-mac*' );
our $mac2name;
my $underscore_whitespace = 0;
foreach my $name_mac ( @name_mac_files ) {
next unless -e $name_mac;
open(my $f, '<'. $name_mac);
my $count = 0;
while(<$f>) {
chomp;
#my ( $ip, $name, $mac ) = split(/ /,$_);
my ( $name, $mac ) = split(/\s+/,$_);
$name =~ s/_/ /g if $underscore_whitespace; # replace underscore with space
$mac = lc($mac);
#$mac2name->{$mac} = $name;
if ( defined $mac2name->{$mac} ) {
if ( $mac2name->{$mac} ne $name ) {
warn "ERROR: GOT $mac with $mac2name->{$mac} and now trying to overwrite it with $name\n";
}
} else {
$mac2name->{$mac} = $name;
}
#$mac_name_use->{$name} = 0;
$count++;
}
warn "## $name_mac $count";
}
sub mac2name {
my ( $mac, $name ) = @_;
$mac = lc($mac);
if ( exists $mac2name->{$mac} ) {
my $mac_name = $mac2name->{$mac};
warn "ERROR: name different $name != $mac_name" if $name && $name ne $mac_name;
return ( $mac, $mac_name );
}
return ( $mac, $name );
}
#warn "# mac2name = ",dump($mac2name) if $debug;
1;