NAME

InternetData::Result - what an address lookup answers

SYNOPSIS

my $result = $client->lookup('146.70.116.130');

$result->ip;                    # '146.70.116.130'
$result->is_anycast;            # 0
$result->location->{country};   # the ISO 3166 country code
$result->asn->{name};           # who runs the announcing network
($result->company // {})->{name};   # who holds the address, on a paid plan or a free key's full answers

$result->is_hosting;            # 1, 0, or undef when your plan omits it
$result->is_hosting // 0;       # read an absent field as false
$result->has('is_hosting');     # 1 if your plan carries it at all

ABSENT IS NOT FALSE

An absent field is one your plan does not include. It never means "we checked and found nothing", so undef and 0 are genuinely different answers.

This is the one place Perl makes it easy to get wrong, because undef, 0, '' and a missing hash key are all false:

if ($result->is_hosting) { ... }        # WRONG: absent and false look alike

if (($result->is_hosting // 0)) { ... } # right: absent reads as false
if ($result->has('is_hosting')) { ... } # right: asks whether it was served

// (defined-or) is the reader for "treat absent as false", and has is the reader for "was this served at all". A result is also a plain hash reference, so exists $result->{is_hosting} is has spelled out and defined $result->{is_hosting} is the same test one level down.

A paid member inside a shared object is absent the same way, so ask with exists: exists $result->location->{city}.

A detail object that is present but empty ({}, and [] for web) means the flag above it is false. A populated one always carries every one of its keys.

METHODS

ip, is_bogon

Always present. is_bogon is set for reserved space, which the client answers itself without a request.

is_tor, is_relay, is_anycast

On every answer, with a key or without one: 1 or 0.

is_vpn, is_resproxy, is_dcproxy, is_mobproxy, is_pubproxy, is_hosting, is_cdn

The paid flags: 1, 0, or undef when your plan omits the field.

is_bot, is_carrier, is_satellite, is_ssh, is_smtp, is_web, is_dns_resolver, is_bittorrent

On a paid plan or a free key's full answers: 1, 0, or undef on an answer of the basics, which does not carry them.

vpn, tor, relay, resproxy, dcproxy, mobproxy, pubproxy, hosting, cdn, bot, carrier, satellite, ssh, smtp, web, dns_resolver, bittorrent

The detail behind each flag, as plain hash references (web an array reference of the web servers found), or undef when your plan omits them. The basics answer tor and relay; a paid plan answers them all. bot names whose bot uses the address (provider, provider_name), its bots as their user agents name them (agents), what they do (categories) and whether the operator vouches for the address (verified, identity, verified_by).

location, asn, hostname

On every answer, with a key or without one. location and asn are plain hash references whose paid members are absent on the basics: location carries the country there and the city, coordinates and the rest on a paid plan or a free key's full answers, and asn its type likewise. hostname is the reverse-DNS name, an empty string where there is none.

company, abuse

The company that uses the address and where to report abuse from it, on a paid plan or a free key's full answers, as plain hash references, or undef on an answer of the basics, which does not carry them: has('company') says which. A served one always carries name and domain, or email, and the rest of each is a paid member as inside location. A bogon's carries every member empty.

my $email = ($result->abuse // {})->{email} // '';

whois, rwhois, hosted_domains

Paid: the WHOIS and RWHOIS records for the range, and how many domains point at the address with the 10 most popular ({total => 4, domains => [...]}), or undef when your plan omits them.

user_agent

What the user agent sent with the lookup names, and whether the address bears it out, as a plain hash reference, or undef on an answer that does not carry it: one to a lookup that sent no user_agent, one without every field, and a bogon's, which is answered locally. It carries agent (the agent the user agent names, such as Googlebot or Chrome, Unknown where it names none), kind (browser, inapp, automation, bot, ai-bot, http-client or unknown) and verdict: verified when the agent's operator vouches for the address as it, spoofed when the operator of a bot that publishes its addresses does not vouch for this one, unverifiable for a bot nothing can confirm, and not_bot for a browser, an app or a script.

my $r = $client->lookup($ip, user_agent => $request->headers->user_agent);
my $verdict = ($r->user_agent // {})->{verdict} // '';
deny() if $verdict eq 'spoofed';

trial_expired

On answers to a key on the free plan only: 0 while its organization's lookups of the UTC day answer every field, 1 once those are used up and the answer has the basics, and undef on any other answer.

cap_reached

On answers to a key on a paid plan only: 0 while the answer has every field, 1 once its organization's overage cap is reached and the answer has the basics, which is not billed, and undef on any other answer.

has($field)

Whether your plan carries $field. Croaks on a name that is not a field.

fields

The field names this answer carried, in wire order.

raw

The decoded response body, untouched. Treat it, and the result itself, as read only: the cache hands the same object to every later caller of an address.