Geoip lookup in ruby
Last update
2023-10-27
2023-10-27
« — »
If you use the ipv4-num database, it gives the IP address ranges in decimal format.
You can then take an incoming IP address and convert it to decimal:
1 2 3 | require 'ipaddr' ip = IPAddr.new "[10.0.2.15](https://10.0.2.15)" ip_int = ip.to_i |
Then you can query the ip-location-db using the decimal (i.e. where ip_int >= ip_range_start
and ip_int <= ip_range_end
).
Source reddit