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, 09: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, 188.8.131.52 - 184.108.40.206. The table structure is like this
ip customer name 220.127.116.11 - 18.104.22.168 name1 22.214.171.124 - 126.96.36.199 name2
Last edited by Anishgiri; 05-20-2014 at 10:20 AM.
05-20-2014, 02:29 PM #2
- Join Date
- May 2005
- Southern tip of Silicon Valley
- Thanked 164 Times in 159 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;