Network

Query IP Information

Query IP address information from ipinfo.io with cnquery

Rely on cnquery to query IP address information from the ipinfo.io service. Get geolocation data, hostname information, and organization details for any IP address.

Requirements

To query IP information with cnquery, you must have:

Optionally, set the IPINFO_TOKEN environment variable for authenticated API access with higher rate limits.

Query IP information

To open a cnquery shell with the ipinfo provider:

cnquery shell ipinfo

You can also run one-off queries:

# Query information about a specific IP
cnquery run ipinfo -c "ipinfo(ip('8.8.8.8')){*}"

# Query your machine's public IP
cnquery run ipinfo -c "ipinfo(){*}"

# Query IP information for all network interfaces
cnquery run -c "network.interfaces.map(ips.map(_.ip)).flat.map(ipinfo(_){*})"

Example queries

Once in the cnquery shell, you can query IP information.

This query retrieves information about your public IP:

cnquery> ipinfo()
ipinfo: {
  returned_ip: "203.0.113.50"
  hostname: "example.host.com"
  city: "San Francisco"
  ...
}

This query retrieves information about a specific IP:

cnquery> ipinfo(ip("8.8.8.8"))
ipinfo: {
  returned_ip: "8.8.8.8"
  hostname: "dns.google"
  city: "Mountain View"
  region: "California"
  country: "US"
  org: "AS15169 Google LLC"
  ...
}

This query checks if an IP is a bogon (private/non-routable address):

cnquery> ipinfo(ip("192.168.1.1")).bogon
ipinfo.bogon: 1

This query retrieves the organization managing an IP:

cnquery> ipinfo(ip("1.1.1.1")).org
ipinfo.org: "AS13335 Cloudflare, Inc."

Exit the cnquery shell

To exit the cnquery shell, either press Ctrl + D or type exit.

Learn more

On this page