NAME

App::ipinfo - a command-line tool for IPinfo.io

SYNOPSIS

Call it as the program:

% ipinfo '%c' [ip addresses]

Do it all at once:

use App::ipinfo;
App::ipinfo->run( \%options, @ip_addresses );

Control most of it yourself:

use App::ipinfo;

my $app = App::ipinfo->new(
	template => '%c',
	token    => ...,
	);

foreach my $ip ( @ip_addresses ) {
	my $info = $app->get_info($ip);
	next unless defined $info;
	$app->output( $app->format($info) );
	}

DESCRIPTION

Formatting

Most of the data provided by IPinfo has an sprintf-style formatting code, and for everything else you can use %j to get JSON that you can format with jq for some other tool.

  • %a - the ASN of the organization

  • %c - the city of the organization

  • %C - the country code of the organization

  • %f - the emoji flag of the country

  • %h - the hostname for the IP address

  • %i - the IP address

  • %j - all the data as JSON, in a UTF-8 decoded string

  • %k - the continent of the organization

  • %L - the latitude of the organization

  • %l - the longitude of the organization

  • %n - the country name of the organization

  • %N - newline

  • %o - the organization name

  • %r - the region of the organization (i.e. state or province)

  • %t - the timezone of the organization (e.g. America/New_York )

  • %T - tab

  • %% - literal percent

Class methods

  • new( HASH )

    Allowed keys:

    • error_fh

      The filehandle to send error output to. The default is standard error.

    • template

      The template.

    • output_fh

      The filehandle to send error output to. The default is standard output.

    • token

      The API token from IPinfo.io.

  • looks_like_template(STRING)

    Returns true if STRING looks like a template. That is, it has a % followed by a non-whitespace character. This will get more sophisticated later.

  • CLASS->run( [TEMPLATE,] IP_ADDRESS [, IP_ADDRESS ... ] )

  • OBJ->run( [TEMPLATE,] IP_ADDRESS [, IP_ADDRESS ... ] )

    Format every IP address according to TEMPLATE and send the result to the output filehandle.

    If the first argument looks like a template (has a %), it is used to format the output. Otherwise, the first argument is taken as the start of the list of IP addresses and the default format is used.

    If the invocant is not a reference, it's used as the class name to build the object. If the invocant is a reference, it's used as the object. These are the same and use all the default settings:

    my $obj = App::ipinfo->new;
    $obj->run( @ip_addresses );
    
    App::ipfinfo->run( @ip_addresses );

Instance methods

  • decode_info

    Fixup some issues in the API response.

  • default_error_fh

    Returns the default for the error filehandle. In this module, it's standard error.

  • default_template

    Returns the default template for output. In this modules, it's %c, for the city. See the "Formats" section.

  • default_output_fh

    Returns the default for the error filehandle. In this module, it's standard error.

  • error(MESSAGE)

    Send the MESSAGE string to the error filehandle.

  • error_fh

    Returns the filehandle for error output.

  • formatter

    Returns the formatter object. In this module, that's an object of String::Sprintf.

  • format( TEMPLATE, IP_INFO )

    Formats a Geo::Details object according to template.

  • get_info(IP_ADDRESS)

  • looks_like_ipv4(IP)

    Returns true if IP looks like an IPv4 address.

  • looks_like_ipv6(IP)

    Returns true if IP looks like an IPv6 address.

  • get_token

    Return the API token. So far, this is just the value in the APP_IPINFO_TOKEN environment variable.

  • output(MESSAGE)

    Send the MESSAGE string to the output filehandle.

  • output_fh

    Return the filehandle for output.

  • template

  • token

    Return the IPinfo.io token

SEE ALSO

SOURCE AVAILABILITY

The main source repository is in Github, and there are backup repos in other services:

COPYRIGHT

Copyright © 2025, brian d foy, all rights reserved.

LICENSE

You can use this code under the terms of the Artistic License 2.