Methods of validating IP address input:
# code to parse for properly formatted hostname or IP address
It's funny how people go to the ends of the Earth and back again to do something as simple as validate an IP address, and they don't even handle all possible valid addresses.
return $_ =~ /^\d\.*$/ && inet_aton($_);
This code uses only standard Perl packages.
Again, N.N.N.N is not the only valid IP address format. Try visiting http://3625994804/ and yo
print "What IP address do you want to allow ssh logins from? ";
$_ = <>;
# This method does not appear to do strict validation of IP addres
# While, it will check for a valod dotted quad entry, it will allo
+w many invalid addresses.
# See the following for additional hints:
# For the time being, this is a sufficient check
my $allowed_ipaddr = inet_aton( $_ );
length($allowed_ipaddr) or die "Sorry, '$_' is not a valid IP addr
$allowed_ipaddr = inet_ntoa($allowed_ipaddr); # convert to dotted
+quad, if necessary.
print " You have authorized the host with IP address $allowed_ipad
+dr to log in via ssh.\n";