Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
IP Lookup - best methods?
Old 07-15-2009, 11:16 PM IP Lookup - best methods?
!dahan!'s Avatar
Average Talker

Posts: 20
Trades: 0
We've been asked to create a special system for certain institutions to be recognised on a closed system by IP Address.

I'm just wondering what the best way would be to store an IP address range in the database so that I can easily get an institution id code from comparing the REMOTE_ADDR server variable against the stored range?

any ideas would be welcome
__________________

Please login or register to view this content. Registration is FREE
!dahan! is offline
Reply With Quote
View Public Profile Visit !dahan!'s homepage!
 
 
Register now for full access!
Old 07-16-2009, 12:25 AM Re: IP Lookup - best methods?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I haven't tried this, but maybe by taking out all the non-numbers and storing as a number? Computers are much faster at sifting through numbers than text. The key thing to making this successful would be ensuring that you stored 12.12.12.12 as 12012012012 so that entries are in proper numerical order.

EDIT: And, putting a UNIQUE index on the field.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-16-2009, 04:05 AM Re: IP Lookup - best methods?
NullPointer's Avatar
Will Code for Food

Posts: 2,781
Name: Matt
Location: Irvine, CA
Trades: 0
I agree with Jeremy that you should store IPs as numbers rather than strings. Another approach, rather than just dropping the decimal and adding a zero where necessary, would be to convert an IP to its decimal numeric equivalent.

An IP address is just a series of four 8-bit binary numbers. Given the full, 8-bit representation of each value, you can drop the decimals and convert the resulting 32-bit binary number to decimal. If you are using PHP there are two functions which will simplify this process for you:

http://us.php.net/manual/en/function.ip2long.php
http://us.php.net/manual/en/function.long2ip.php
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to IP Lookup - best methods?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17717 seconds with 12 queries