Skip to content

Conversation

@Bajusz15
Copy link
Contributor

@Bajusz15 Bajusz15 commented Nov 13, 2025

Adds ipinfo provider. Initially I added functionality to route the request through an interface, but after alignment we decided to keep it simple, ipinfo can be used to query ipinfo.io for any ip.

If the envrionment variable IPINFO_TOKEN is set we can use the paid sdk version, otherwise we fall back to the free deprecated API (simply calling ipinfo.io/).

To get public IP of the machine we are running ipinfo from, we need to call ipinfo with an empty address.

Usage:

go run ./apps/cnquery/cnquery.go run -c "ipinfo(ip('1.1.1.1'))"
ipinfo: ipinfo returned_ip=1.1.1.1 hostname="one.one.one.one" bogon=false
 
go run ./apps/cnquery/cnquery.go run -c "ipinfo"   
ipinfo: ipinfo returned_ip=95.XX.XXX.19 hostname="REDACTED.kabel-deutschland.de" bogon=false

go run ./apps/cnquery/cnquery.go run -c "ipinfo(ip('192.168.178.86'))"
ipinfo: ipinfo returned_ip=192.168.178.86 hostname="" bogon=true

go run ./apps/cnquery/cnquery.go run -c "network.routes.defaults.map(iface.ips.map(_.ip)).flat.map(ipinfo(_){*})"
.....

@Bajusz15 Bajusz15 changed the title Add resource ipinfo New provider ipinfo Nov 13, 2025
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 13, 2025

Test Results

4 574 tests  ±0   4 570 ✅ ±0   2m 15s ⏱️ -15s
  409 suites ±0       4 💤 ±0 
   30 files   ±0       0 ❌ ±0 

Results for commit 75fe0d1. ± Comparison against base commit 8a0946d.

♻️ This comment has been updated with latest results.

@github-actions

This comment has been minimized.

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first version @Bajusz15 I added some feedback

var Config = plugin.Provider{
Name: "ipinfo",
ID: "go.mondoo.com/cnquery/v12/providers/ipinfo",
Version: "10.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be version 12

Connectors: []plugin.Connector{
{
Name: "ipinfo",
Use: "ipinfo",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proper description required


go 1.25.1

require go.mondoo.com/cnquery/v12 v12.9.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a relative import similar to the other providers

url = "https://ipinfo.io"
} else {
// Query for specific IP
url = fmt.Sprintf("https://ipinfo.io/%s", queryIP.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why we are not using https://github.com/ipinfo/go? This would also help us to implement the token support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not working without a real token when I was testing it locally. I removed it in this commit, but this is still an early draft and needs lot of rework. If I can find a way to use the sdk without a real token I will change it back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty token works without any problem:

const token = ""

// params: httpClient, cache, token. `http.DefaultClient` and no cache will be used in case of `nil`.
client := ipinfo.NewClient(nil, nil, token)

const ip_address = "8.8.8.8"
info, err := client.GetIPInfo(net.ParseIP(ip_address))

if err != nil {
panic(err)
}

fmt.Println(info)

@Bajusz15 Bajusz15 changed the title New provider ipinfo Add new provider ipinfo Nov 20, 2025
@Bajusz15 Bajusz15 marked this pull request as ready for review November 20, 2025 12:35
@Bajusz15 Bajusz15 changed the title Add new provider ipinfo ⭐ Add provider ipinfo Nov 20, 2025
)

// getIPInfoToken returns the IPINFO_TOKEN from environment variable, cached after first read
func getIPInfoToken() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done when we start the connection, then we also do not need to use locks https://github.com/mondoohq/cnquery/pull/6176/files#diff-59130fb879bd3dcc44bb675d913b5a3f8019f8cc4f814d53bcc0f4ea39b0ab5aR18-R28


This provider makes public IP address information accessible from ipinfo.io.

It provides a connector for querying IP information via the ipinfo.io API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add examples here how to use it and also include sample MQL. https://github.com/mondoohq/cnquery/tree/main/providers/shodan is a good example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically would also love to see some examples that use the cross provider connection eg. with local interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated readme now

^\.github/workflows/.*\.yaml
_release_template_file.md
ignore$
ipinfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should merge into main, not another branch

url = "https://ipinfo.io"
} else {
// Query for specific IP
url = fmt.Sprintf("https://ipinfo.io/%s", queryIP.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty token works without any problem:

const token = ""

// params: httpClient, cache, token. `http.DefaultClient` and no cache will be used in case of `nil`.
client := ipinfo.NewClient(nil, nil, token)

const ip_address = "8.8.8.8"
info, err := client.GetIPInfo(net.ParseIP(ip_address))

if err != nil {
panic(err)
}

fmt.Println(info)

@Bajusz15 Bajusz15 changed the base branch from mate/849/ipv4v6 to main November 20, 2025 19:12
@Bajusz15 Bajusz15 force-pushed the mate/849/externalIP branch from 338d9e3 to 4fe5b09 Compare November 20, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants