Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Luis- on February 25, 2018, 03:25:45 PM

Title: IP Ranges
Post by: Luis- on February 25, 2018, 03:25:45 PM
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;
SELECT * FROM ip_address WHERE IP BETWEEN '123.45.0.0' AND '123.45.255.255'
Let's say I submit 192.168.0.1, i'd like to return every IP that has 192.168.0.x
Title: Re: IP Ranges
Post by: turtlemanmike on May 08, 2018, 03:05:07 PM
Will the LIKE statement work here - LIKE "%192.123..12%"
Title: Re: IP Ranges
Post by: vbgamer45 on May 08, 2018, 04:10:10 PM
No it would not.
Title: Re: IP Ranges
Post by: Sir Osis of Liver on May 08, 2018, 05:34:10 PM
https://stackoverflow.com/questions/24179437/mysql-check-if-an-ip-address-is-in-range
Title: Re: IP Ranges
Post by: albertlast on May 12, 2018, 03:12:32 AM
Just for the records,
in smf 2.1 the solution would be:

$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',
)


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