Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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: # http://www.perlmonks.org/index.pl?node_id=513811 # http://www.perlmonks.org/index.pl?node=221512 # 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?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-10-02 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (48 votes), past polls