File: gen_macs.pl

package info (click to toggle)
libnet-mac-perl 2.103622-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 1,709; makefile: 2
file content (36 lines) | stat: -rwxr-xr-x 874 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl 

use strict; 
use warnings; 
use Getopt::Long; 
use Data::Dumper;

my ($count, $base); 
&Getopt::Long::GetOptions( 
	'count=i' => \$count, 
	'base=i' => \$base
); 

my @delimiter = ('.', ':', '-', ' '); 
my $z = 1; # $z == 1 means zero padding 
my %mac; 
for (my $i=0; $i<$count; $i++) { 
	my $mac = ''; 
	my $delimiter = $delimiter[int(rand(4))];
	for (my $j=0; $j<6; $j++) { # 6 octets
		for (my $k=0; $k<2; $k++) { 
			my $random = sprintf('%x', int(rand(16))); 
			if (($k == 0) && ($random eq '0') && ($z == 0)) { 
				next; # Zero padding is turned off
			}
			$mac .= $random; 
		} 
		unless ($j == 5) { # Avoid trailing delimiter
			$mac .= $delimiter; 
		}
	}
	$mac{$mac} = {base => $base, bit_group => 16, delimiter => $delimiter, zero_padding => $z};
	$z = int(rand(2)); 
} 
my $dump = Data::Dumper->new([\%mac], ['mac']); 
print $dump->Dump();