Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

IP address matching

by oliverm (Initiate)
on Jun 04, 2004 at 22:05 UTC ( #361232=perlquestion: print w/replies, xml ) Need Help??

oliverm has asked for the wisdom of the Perl Monks concerning the following question:

I need a regexp to match an ip address Oliver Meyer

Replies are listed 'Best First'.
Re: IP address matching
by Abigail-II (Bishop) on Jun 04, 2004 at 22:39 UTC
    use Regexp::Common; /$RE{net}{IPv4}/ and print "Contains a valid IP address\n"; /$RE{net}{IPv4}{hex}/ and print "Contains a valid IP address in hex\n" +; /$RE{net}{IPv4}{oct}{-sep => ':'}/ and print "..."; # Etc.


Re: IP address matching (potentially relevant thread)
by ybiC (Prior) on Jun 05, 2004 at 01:11 UTC
Re: IP address matching
by u235sentinel (Hermit) on Jun 04, 2004 at 23:52 UTC
    I was wondering if you have written any code so we can help you.

    I've written something like this a few times recently. No error checking but then again I was pulling from my apache access_log. I wanted it all including any invalid. Let us know what you have tried.
Re: IP address matching
by Anonymous Monk on Jun 04, 2004 at 22:15 UTC
    Thats trivial and I wont give you the spoiler. But consider first - IP addresses can come in one or two forms. IP6, IP4 etc. How broad do you want your match to be? Any valid IP? Or just ones from sensible domains?
      IPv4, and i want it to be any valid IP

        and if you want to be extra careful (or just plain pedantic :)...

        some IP addresses while valid in form are not valid in practice. these are the martians and the unallocated.

        the martians are reserved addresses that shouldn't be seen on the internet as a whole. but some of them can be used on local networks.

        the unallocated are IP addresses that have not been allocated out of the global pool. these you shouldn't see at all (and shouldn't accept either).

        you can find the current lists through a handy whois query.

        $ whois -h fltr-martian filter-set: fltr-martian filter: {^+ ,^+ ,^+ ,^+ ,^+ ,^+ ,^+ ,^+ ,^+ } descr: Special use and reserved IPv4 prefixes. remarks: For the complete set of bogons, please see: fltr-unallocated - unallocated prefixes. fltr-bogons - fltr-unallocated + fltr-martian. admin-c: Rob Thomas RT624 tech-c: Rob Thomas RT624 notify: mnt-by: MAINT-BOGON-FILTERS changed: 20021229 changed: 20021230 changed: 20021230 source: RADB ...

        do the same to find fltr-unallocated.

Re: IP address matching
by CountZero (Bishop) on Jun 04, 2004 at 22:48 UTC
    It is considered polite and good form to at least start your request with a nice salutation to the Monks and show some effort in solving your problem.


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://361232]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2022-05-21 09:01 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.