Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; print "What IP address/Domain Name do you want to access: "; $_ = <>; my $ip = SanitizeIP($_); print "$ip is sane.\n"; exit; sub SanitizeIP { chomp ($_); my ($a,$c,$d,$e,$f); my $b = 0; if ($_ =~ /[a-zA-Z]+/) { print "$_\n"; $_ = gethostbyname($_); ($c,$d,$e,$f) = unpack('C4', $_); $_ = $c . "." . $d . "." . $e . "." . $f; } my @_temp = split(/\./,$_); undef $_; foreach $a(@_temp) { if ($a =~ /\b\d\b|\b\d\d\b|\b\d\d\d\b/) { if (($a >= 0) and ($a <= 255)) { $_ = $_ . int($a); $_ = $_ . "." unless ($b > 2); $b++; } else { print "This is an illegal IP address -- or it sure see +ms like one.\n"; exit; } } else { print "This is an illegal IP address -- or it sure seems l +ike one.\n"; exit; } } if (($_ eq "") or ($_ eq " ")) { print "The Address did not resolve, or there was something wro +ng with what you typed.\n"; exit; } return $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IP Address Sanity
by jdporter (Paladin) on Nov 07, 2002 at 23:34 UTC | |
|
Re: IP Address Sanity
by Wonko the sane (Curate) on Nov 07, 2002 at 22:33 UTC | |
by demerphq (Chancellor) on Dec 16, 2002 at 22:28 UTC | |
by Wonko the sane (Curate) on Dec 27, 2002 at 00:35 UTC | |
by rob_au (Abbot) on Dec 27, 2002 at 01:15 UTC | |
by Wonko the sane (Curate) on Dec 27, 2002 at 13:21 UTC | |
|
Re: IP Address Sanity
by fokat (Deacon) on Nov 08, 2002 at 04:51 UTC | |
|
Re: IP Address Sanity
by FamousLongAgo (Friar) on Nov 07, 2002 at 22:42 UTC | |
|
Re: IP Address Sanity
by lestrrat (Deacon) on Nov 07, 2002 at 22:42 UTC | |
by FamousLongAgo (Friar) on Nov 07, 2002 at 22:46 UTC |