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. Use the IPinfo provider inside your own policies to check whether IPs in your environment match expected geographies, organizations, or routability.

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

Open a cnspec shell with the IPinfo provider:

cnspec shell ipinfo

Or 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

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