zuinc has asked for the wisdom of the Perl Monks concerning the following question:
So, for example, if the user enters 12.34.56.78, the program will store 12.34.56 as the subnet and then should compare 12.34.56 with the list subnets.list and return either a true or false value. Please HELP! Thanks. Zuinc#/usr/local/bin/perl # Creates a list of all subnets $sn = 0xffff & system("ypcat hosts | cut -f1-3 -d \".\" | sort -u | so +rt -k 1n,1 n -k 2n,2n -k 3n,3n -t \".\" -r>subnets.list"); # User is prompted to anter an IP address open(CHECK, ">check.list") || die "ERROR! This file cannot be created! +\n"; print "Enter an IP address.\n"; $ip = <STDIN>; chomp ($ip); $partial = rindex($ip, "."); $ip_subnet = substr($ip, 0, $partial); chomp ($ip_subnet); print CHECK "$ip_subnet\n"; # Checkpoint - prints subnet # Match entered subnet to active subnet list open(SUBNET, "subnets.list") || die "Unable to open file: subnets.list +\n"; while (<SUBNET> ) { if ($ip_subnet eq $subnet) { print "PASS\n"; } else { print "FAIL\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: User input compared with generated list
by PrimeLord (Pilgrim) on Apr 03, 2002 at 18:09 UTC | |
by zuinc (Novice) on Apr 03, 2002 at 18:44 UTC | |
|
Re: User input compared with generated list
by RMGir (Prior) on Apr 03, 2002 at 18:23 UTC | |
by zuinc (Novice) on Apr 03, 2002 at 19:06 UTC | |
by RMGir (Prior) on Apr 03, 2002 at 19:34 UTC | |
|
Re: User input compared with generated list
by stephen (Priest) on Apr 03, 2002 at 18:33 UTC |