C Library
PHP Module
Perl Module
Ruby Library
Python Library
Apache Module
Nginx Module
Node.js Module
Cocoa / Objective C Library
Pascal Library
D Library
Go Package
Erlang Module
Haskell Package
Debian Package
Lua Package
Kotlin Module
Scala Library
OpenResty Package
Splunk Add-on
Apache Kafka Transform
OCaml Module
Deno Module
R Package
.NET Component
Java Component
HTTP Module
ActiveX / COM DLL
IP2Location IP Geolocation Ruby Library
The IP2Location IP Geolocation Ruby library helps users to get IP geolocation data of an IP address, such as the country, region, district, city, coordinates (longitude / latitude), ZIP code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation usage type, address type, IAB category and ASN that any IP address or hostname originates from. It has been optimized for speed and memory utilization. Developers can use the API to query all IP2Location™ binary databases for IPv4 and IPv6 address.
- Download the Ruby package above.
- Decompress the package.
tar xvfz ip2location-ruby-x.x.x.tar.gz
- Install ip2location_ruby using RubyGems.
gem install ip2location_ruby
- Run the script
ruby -rubygems example.rb
require 'ip2location_ruby'
# BIN Database
i2l = Ip2location.new.open("./data/IP2LOCATION-LITE-DB1.IPV6.BIN")
record = i2l.get_all('8.8.8.8')
print 'Country Code: ' + record['country_short'] + "\n"
print 'Country Name: ' + record['country_long'] + "\n"
print 'Region Name: ' + record['region'] + "\n"
print 'City Name: ' + record['city'] + "\n"
print 'Latitude: '
print record['latitude']
print "\n"
print 'Longitude: '
print record['longitude']
print "\n"
print 'ISP: ' + record['isp'] + "\n"
print 'Domain: ' + record['domain'] + "\n"
print 'Net Speed: ' + record['netspeed'] + "\n"
print 'Area Code: ' + record['areacode'] + "\n"
print 'IDD Code: ' + record['iddcode'] + "\n"
print 'Time Zone: ' + record['timezone'] + "\n"
print 'ZIP Code: ' + record['zipcode'] + "\n"
print 'Weather Station Code: ' + record['weatherstationname'] + "\n"
print 'Weather Station Name: ' + record['weatherstationcode'] + "\n"
print 'MCC: ' + record['mcc'] + "\n"
print 'MNC: ' + record['mnc'] + "\n"
print 'Mobile Name: ' + record['mobilebrand'] + "\n"
print 'Elevation: '
print record['elevation']
print "\n"
print 'Usage Type: ' + record['usagetype'] + "\n"
print 'Address Type: ' + record['addresstype'] + "\n"
print 'Category: ' + record['category'] + "\n"
print 'District: ' + record['district'] + "\n"
print 'ASN: ' + record['asn'] + "\n"
print 'AS: ' + record['as'] + "\n"
i2l.close()
# Web Service
ws = Ip2locationWebService.new('demo', 'WS25')
record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
print record
print "\n"
print ws.get_credit()
Discover Your User Locations
Retrieve geolocation data for FREE now!