/    Sign up×
Community /Pin to ProfileBookmark

Find an IP address in a set (looking for a pro’s advice)

I am looking to to store several sets of ‘IP addresses ranges’ (e.g: a.b.c.d to w.x.y.z) in a table. I would then like to take a given IP address and search MySQL to find whether the IP address exist in the database.

As of now, the best approach I can think of is to

[LIST]

  • [*]

    store the IP address ranges as regular expressions in the db


  • [*]

    php script grabs all regexes and stores in an array


  • [*]

    php scripts loops through each array entry, and checks for match


  • [/LIST]

    Is there a better way?

    to post a comment
    PHP

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @chazzyApr 21.2008 — if you're only dealing with ipv4, you'd be better off storing as the 4 separate octets (ie split the IP at the .) for both the low end and high end of the range. querying against that should be easier.

    even if you're dealing with ipv6, you might get away with this same approach, but you need to deal with hex #'s as well.
    ×

    Success!

    Help @ilbonparaurti spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...