Re: using a list
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 08:36:57 GMT
corefile@xxxxxxxxx wrote:
On Feb 27, 2:36 pm, "John W. Krahn" <some...@xxxxxxxxxxx> wrote:
#!/usr/bin/perl
use warnings;
use strict;
use Socket;
my $ip = unpack 'N', inet_aton '192.168.100.1'; #first ip
my $number = 254; #number of ips
my @allports = ( 25, 110, 443, 179 ); #listening ports
my $forward = '10.100.100.1'; # static ip everything get forwarded to
my $fport = 10001; # starting port that @allports will
# forward to running on fip
my $file = 'somefile.txt';
open my $FD, '>>', $file or die "Cannot open '$file' $!";
for ( 1 .. $number ) {
my $addr = inet_ntoa pack 'N', $ip;
for my $port ( @allports ) {
print $FD "$addr $port maps to $forward $fport\n";
++$fport;
}
++$ip;
}
close $FD;
__END__
perfect that worked great, one thing I forgot. I need to also have a
variable that takes the date command and makes a name for it.
I need to use the month/date/time/year + a incrementing number, so
building on what we have:
rule 022715362007_1 192.168.100.1 25 maps to 10.100.100.1 20001
rule 022715362007_2 192.168.100.1 110 maps to 10.100.100.1 20002
rule 022715362007_3 192.168.100.1 443 maps to 10.100.100.1 20003
rule 022715362007_4 192.168.100.1 179 maps to 10.100.100.1 20004
rule 022715362007_5 192.168.100.2 25 maps to 10.100.100.1 20005
rule 022715362007_6 192.168.100.2 110 maps to 10.100.100.1 20006
rule 022715362007_7 192.168.100.2 443 maps to 10.100.100.1 20007
rule 022715362007_8 192.168.100.2 179 maps to 10.100.100.1 20008
rule 022715362007_9 192.168.100.3 25 maps to 10.100.100.1 20009
#!/usr/bin/perl
use warnings;
use strict;
use Socket;
my ( $min, $hour, $day, $mon, $year ) = ( localtime )[ 1 .. 5 ];
my $date = sprintf '%02d%02d%02d%02d%04d_', $mon + 1, $day, $hour, $min,
$year + 1900;
my $ip = unpack 'N', inet_aton '192.168.100.1'; #first ip
my $number = 254; #number of ips
my @allports = ( 25, 110, 443, 179 ); #listening ports
my $forward = '10.100.100.1'; # static ip everything get forwarded to
my $fport = 10000; # starting port that @allports will
# forward to running on fip
my $incr = 1;
my $file = 'somefile.txt';
open my $FD, '>>', $file or die "Cannot open '$file' $!";
for ( 1 .. $number ) {
my $addr = inet_ntoa pack 'N', $ip;
for my $port ( @allports ) {
print $FD "rule $date$incr $addr $port maps to $forward ", $fport +
$incr, "\n";
++$incr;
}
++$ip;
}
close $FD;
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- References:
- using a list
- From: corefile
- Re: using a list
- From: John W. Krahn
- Re: using a list
- From: corefile
- using a list
- Prev by Date: Re: decode a string to "Perl's internal form" without Encode module?
- Next by Date: change chr(9) ?
- Previous by thread: Re: using a list
- Next by thread: Re: using a list
- Index(es):
Relevant Pages
|