Re: using a list



<corefile@xxxxxxxxx> wrote in message
news:1172614368.083420.209560@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Trying to create a way to create a list of ip's port
Does this code even run?

$ip = 192.168.100.1; #first ip
I have no idea what this does. I guess you want "192.168.100.1"

$nip = 254; #number of ips
Why this? It isn't used

@allports = ("25", "110", "443", "179"); #listening ports
$fip = 10.100.100.1; # static ip everything get forwarded to
Same here.

$fport = 10001; # starting port that @allports will forward to running
on fip
$file = somefile.txt;




for ( 1..$n ) {
What's $n? Where is it declared.

$ip =~ s/\.(\d+)$/.$_/;
$fport = $fport++;

open (FD, ">>", $file);
printf (FD "$ip maps to $fip $fport\n");
close (FD);
}


I can't figure out how to implement the @allports part. As I'm a total
noob this is probably not the most efficient way but as long as it
work thats fine for me.

Does it? This code runs? Wow.

If I understand you correctly you want something like:

#!/usr/bin/perl
use warnings;
use strict;
my $ip = "192.168.100"; #first ip
my @allports = ("25", "110", "443", "179"); #listening ports
my $fip = "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";

foreach my $port (@allports) {

open (FD, ">>", $file);
print FD "$ip.$port maps to $fip $fport\n";
close (FD);
$fport++;

}



.