Select record between two IP ranges

前端 未结 8 2141
遇见更好的自我
遇见更好的自我 2021-02-19 05:14

I have a table which stores a ID, Name, Code, IPLow, IPHigh such as:

1, Lucas, 804645, 192.130.1         


        
8条回答
  •  难免孤独
    2021-02-19 05:23

    select *
    from ip a
    join ip_details b
    on a.ip_address >= b.ip_start
    and a.ip_address <= b.ip_end;
    

    In this, table "a" contains list of IP address and table "b" contains the IP ranges.

    Instead of converting the ip address to numeric we can directly compare the string, it will do a byte by byte comparison.

    This is working for me(PostgreSQL).

提交回复
热议问题