in reply to Re^2: Automatic IP address Generation
in thread Automatic IP address Generation
#!/usr/bin/perl use strict; use warnings; use Socket qw( inet_aton inet_ntoa ); sub fr_dotted { unpack 'N', inet_aton @_ ? $_[0] : $_ } sub to_dotted { inet_ntoa pack 'N', @_ ? $_[0] : $_ } my $next = fr_dotted('100.1.3.41'); my $max = fr_dotted('100.1.3.50'); while (<>) { chomp; my ($host) = split(' '); die("Exceed max\n") if $next > $max; my $addr = $next++; print($host, ' ', to_dotted($addr), "\n"); }
renum.pl infile > outfile -or- perl -i.bak renum.pl file
Untested.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Automatic IP address Generation
by ajd335 (Novice) on Jul 30, 2008 at 22:53 UTC | |
by ikegami (Patriarch) on Jul 30, 2008 at 23:45 UTC | |
by ajd335 (Novice) on Jul 31, 2008 at 15:20 UTC | |
|
Re^4: Automatic IP address Generation
by ajd335 (Novice) on Jul 30, 2008 at 20:56 UTC | |
by ikegami (Patriarch) on Jul 30, 2008 at 23:47 UTC |