Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

maggotbrain's scratchpad

by maggotbrain (Monk)
on Jan 29, 2007 at 18:52 UTC ( #597145=scratchpad: print w/replies, xml ) Need Help??

Methods of validating IP address input: # code to parse for properly formatted hostname or IP address
print "What IP address do you want to allow ssh logins from? "; $_ = <>; chomp($_); # This method does not appear to do strict validation of IP addres +ses # 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 +ess.\n"; $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";
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. use Socket; sub IsValidIP { return $_[0] =~ /^\d\.*$/ && inet_aton($_[0]); } download 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
Log In?

What's my password?
Create A New User
and monks are getting baked in the sun...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2018-01-17 04:21 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (196 votes). Check out past polls.