×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help! I need a function to look up the geography for an IP address

Help! I need a function to look up the geography for an IP address

Help! I need a function to look up the geography for an IP address

(OP)
Hi all...

I need help in writing a FUNCTION that will take an IP address and look it up in another table and return its corresponding geography values.(

A function is needed as I have millions of records to lookup and brute force SQL does not perform well.)

source record:

IP Address    Date
155.44.33.91  4/1/2011

lookup table:

start_ip      end_ip            city     state  zip
155.44.33.1   155.93.22.200     lakeland tx     55495
197.65.39.8   198.33.95.12      plano    ca     85167

Can someone help me with an answer?  Thanks!

RE: Help! I need a function to look up the geography for an IP address

Hi

Just a simple query like this could not be optimized neither with a stored function :

CODE

select
*
from adventurous1_table
where '155.44.33.91' between start_ip and end_ip
So what should actually happen with the result of the lookup ?
 

Feherke.
http://free.rootshell.be/~feherke/

RE: Help! I need a function to look up the geography for an IP address

(OP)
Result would be the original ip address and the extended attributes of the ip address, i.e. city, state, zip.

RE: Help! I need a function to look up the geography for an IP address

Hi

That is not a reason to use stored function. There is nothing a function can do and a regular query can not.
 

Feherke.
http://free.rootshell.be/~feherke/

RE: Help! I need a function to look up the geography for an IP address

Hi

Quote (adventurous1):

A function is needed as I have millions of records to lookup and brute force SQL does not perform well.
From another point of view : if your current query is slow, post it so we can analyze it. Also post the exact table structure including constraints and indexes.
 

Feherke.
http://free.rootshell.be/~feherke/

RE: Help! I need a function to look up the geography for an IP address

(OP)
A function will be more efficient going through a collection of records.  The query basically is a join on ip address to retrieve extended attributes per above.

select a.ip_address, b.city, b.state, b.zip
from ip_address
where a.ip_address is between b.start_ip and end_ip

There has to be a better way of doing this, as the performance over millions of records is horrible.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close