Advertisement:

Author Topic: IP Ranges  (Read 1635 times)

Offline Luis-

  • Semi-Newbie
  • *
  • Posts: 92
  • Gender: Male
IP Ranges
« 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;
Code: [Select]
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

Offline turtlemanmike

  • Newbie
  • *
  • Posts: 1
Re: IP Ranges
« Reply #1 on: May 08, 2018, 03:05:07 PM »
Will the LIKE statement work here - LIKE "%192.123..12%"

Online vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,398
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: IP Ranges
« Reply #2 on: May 08, 2018, 04:10:10 PM »
No it would not.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,152
  • 'Tis the gift to be simple (duh)

Offline albertlast

  • Development Contributor
  • Jr. Member
  • *
  • Posts: 330
Re: IP Ranges
« Reply #4 on: May 12, 2018, 03:12:32 AM »
Just for the records,
in smf 2.1 the solution would be:

Code: [Select]
$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.