in reply to Re: How to increment a MAC Address?
in thread How to increment a MAC Address?
To increment a MAC Address, you need to convert HEX to DEC, Add AND convert DEC to HEX...
I propose this code.
I think others improve are possible, but it do a task.sub addmac { my ( $mac, $add ) = @_; $mac =~ s/://g; my $dec = hex($mac); $mac = sprintf("%012x", $dec+$add); return join(":", $mac =~ /(..)/g ); } my $mac = '00:00:00:00:00:f1'; foreach ( 1 .. 32 ) { $mac = addmac($mac,$_*4); print "$mac\n"; }
... 00:00:00:00:01:a5 00:00:00:00:01:cd 00:00:00:00:01:f9 00:00:00:00:02:29 00:00:00:00:02:5d ... 00:00:00:00:03:9d 00:00:00:00:03:e9 00:00:00:00:04:39 00:00:00:00:04:8d
--
Marco Antonio
Rio-PM
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How to increment a MAC Address?
by merlyn (Sage) on Jun 16, 2005 at 17:08 UTC | |
by mda2 (Hermit) on Jun 16, 2005 at 17:47 UTC | |
by merlyn (Sage) on Jun 16, 2005 at 17:53 UTC | |
Re^3: How to increment a MAC Address?
by ikegami (Patriarch) on Jun 17, 2005 at 23:13 UTC |
In Section
Seekers of Perl Wisdom