Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: IPv4 regex (Net::IPv4Addr)

by ryan (Pilgrim)
on Feb 18, 2001 at 18:38 UTC ( #59254=note: print w/ replies, xml ) Need Help??


in reply to Re: IPv4 regex (Net::IPv4Addr)
in thread IPv4 regex

I got the module and this is how they do it:

my $ip_rgx = "\\d+\\.\\d+\\.\\d+\\.\\d+"; sub ipv4_chkip($) { my ($ip) = $_[0] =~ /($ip_rgx)/o; return undef unless $ip; # Check that bytes are in range for (split /\./, $ip ) { return undef if $_ < 0 or $_ > 255; } return $ip; }
Perfect, I'm not going to use the module for my application though because I wanted it to run off standard packaged modules so some totally inept computer users could make use of the script without my assitance. The code however may be making an appearance -- Thanks.


Comment on Re: IPv4 regex (Net::IPv4Addr)
Download Code
(tye)Re: IPv4 regex (Net::IPv4Addr)
by tye (Cardinal) on Feb 19, 2001 at 01:00 UTC

    Heh. I just wanted to note that the test for $_ < 0 is a waste since nothing matching \d+ can be negative.

            - tye (but my friends call me "Tye")
      perl -e 'use integer; print 3000000000 + 1'

        The code in question didn't use integer, and "3000000000 + 1" doesn't match \d+, but other than that, uh, yeah, I suppose you'd want to defend against such values in your IP addresses. (:

                - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://59254]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-08-31 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls