Prerequisites
- Ruby 3.0+ with
ip-api-ioinstalled - A free ip-api.io API key
Autonomous system with asn
Returns the ASN, owning organization, network range, and country for an IP — and
whether it belongs to a datacenter. Absent fields return nil.
client = Ipapi::Client.new(api_key: ENV.fetch("IP_API_IO_KEY"))
asn = client.asn("8.8.8.8")
puts asn.asn # 15169
puts asn.organization # "Google LLC"
puts asn.datacenter? # true Domain registration with whois
WHOIS record for a domain: registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text.
whois = client.whois("example.com")
puts whois.registrar&.name
puts whois.registered_on # "1995-08-14"
puts whois.name_servers DNS with reverse_dns, forward_dns & mx_records
Resolve a PTR record, resolve a hostname to addresses, or list a domain's mail servers.
rdns = client.reverse_dns("8.8.8.8")
puts rdns.hostname # "dns.google"
fdns = client.forward_dns("dns.google")
fdns.addresses.each do |record|
puts "#{record.type} #{record.address} #{record.ttl}" # "A" "8.8.8.8" 300
end
mx = client.mx_records("example.com")
mx.mx_records.each do |record|
puts "#{record.priority} #{record.hostname} #{record.ttl}"
end