General Community > Scripting Help

IP Ranges

(1/1)

Luis-:
Hey!

Basically I have a code that allows me to submit an IP address and return information from that IP address.

What I want to do is return all the rows that have the IP range that I submit.

Take this query as an example;

--- Code: ---SELECT * FROM ip_address WHERE IP BETWEEN '123.45.0.0' AND '123.45.255.255'
--- End code ---
Let's say I submit 192.168.0.1, i'd like to return every IP that has 192.168.0.x

turtlemanmike:
Will the LIKE statement work here - LIKE "%192.123..12%"

vbgamer45:
No it would not.

Sir Osis of Liver:
https://stackoverflow.com/questions/24179437/mysql-check-if-an-ip-address-is-in-range

albertlast:
Just for the records,
in smf 2.1 the solution would be:


--- Code: ---$smcFunc['db_query']('','
SELECT *
FROM ip_address
WHERE ip BETWEEN {inet:start_ip} and {inet:end_ip}',
array(
  'start_ip' => '123.45.0.0',
  'end_ip' => '123.45.255.255',
)
--- End code ---

But works only when you use the inet field type from smf2.1.

Navigation

[0] Message Index

Go to full version