Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: COVID-19 data analytics, cryptography, and some things you should know

by AnomalousMonk (Bishop)
on Apr 05, 2020 at 05:59 UTC ( #11115070=note: print w/replies, xml ) Need Help??


in reply to COVID-19 data analytics, cryptography, and some things you should know

$ip =~ m/^\d+\.\d+\.\d+\.\d+$/

If you're worried about a valid IPv4 dotted-decimal IP address, take a look at Regexp::Common::net (and at Regexp::Common to see how to invoke said module). And I'm sure there are other, similar CPAN resources available.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: COVID-19 data analytics, cryptography, and some things you should know
by tachyon-II (Chaplain) on Apr 05, 2020 at 11:28 UTC

    There are multiple was to check an IP address and Regexp::Common:net would be one of the least efficient. It's rather missing to point of the task at hand.

    A far better, far faster, far lighter option would be Data::Validate::IP but, like I said, this is not a request for how to validate an IP. It's a request about hacking crytpo.

    The null return value (that goes into the DB is 100% about security and 0% about validity).

    The presented stings come from NGINX so don't really need any validation. They come from the socket directing the traffic...

      "The presented stings come from NGINX so don't really need any validation."

      And yet, you have code that identifies the IP type by a regexp, and throws if it is not "valid."

      What do you think is "far better, far faster, far lighter" about

      sub _slow_is_ipv4 { shift if ref $_[0]; my $value = shift; return undef unless defined($value); my (@octets) = $value =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1, +3})$/; return undef unless (@octets == 4); foreach (@octets) { return undef if $_ < 0 || $_ > 255; return undef if $_ =~ /^0\d{1,2}$/; } return join('.', @octets); }
      in Data::Validate::IP (which has a dependency on NetAddr::IP)

      as compared to the code in Regexp::Common::net?

      Snarky reply to AnomalousMonk's attempt to offer assistance. Downvoted. (And the reply to bliako.)


      The way forward always starts with a minimal test.
        ... and throws if it is not "valid."

        ... and may accept what is not valid, e.g., '9999.9999.9999.9999' :)


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2020-07-03 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?