Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: how to query ip in p range
05-20-2014, 10:46 AM #1
- Join Date
- May 2010
- Thanked 0 Times in 0 Posts
how to query ip in p range
I can't figure this. Can this be done alone with mysql, or there are somethings I need to do with php script.Let say I have many ip range stored in the database one of them is, 22.214.171.124 - 126.96.36.199. The table structure is like this
ip customer name 188.8.131.52 - 184.108.40.206 name1 220.127.116.11 - 18.104.22.168 name2
Last edited by Anishgiri; 05-20-2014 at 11:20 AM.
05-20-2014, 03:29 PM #2
- Join Date
- May 2005
- Southern tip of Silicon Valley
- Thanked 180 Times in 175 Posts
That's a very poor way to store the IP ranges. You should split that into 2 fields such as start_IP and end_IP. It would also be better to store them as integers rather than strings.
Assuming you made those changes, then the select statement would be:
If you don't make those changes, then we might be able to work up a complex query that does what you want, but it wouldn't be very maintainable.Code:select customer_name from tablename where start_IP >= $IP and end_IP <= $IP;