Networking

Query IP Information with cnspec

Query IP address information from ipinfo.io with cnspec

Query IP address information from the ipinfo.io service with cnspec. Get geolocation data, hostname information, and organization details for any IP address.

Prerequisites

To query IP information with cnspec, you must have:

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

Query IP information

To open a cnspec shell with the ipinfo provider:

cnspec shell ipinfo

You can also run one-off queries:

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

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

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

Example queries

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

Retrieve your public IP information

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

Retrieve information about a specific IP

cnspec> 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"
  ...
}

Check if an IP is a bogon (private/non-routable)

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

Retrieve the organization managing an IP

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

Learn more

On this page