Skip to content

Commit cf50263

Browse files
authored
⭐ Add provider ipinfo (#6176)
1 parent 8a0946d commit cf50263

File tree

16 files changed

+1666
-0
lines changed

16 files changed

+1666
-0
lines changed

.github/actions/spelling/excludes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@
8383
^\.github/workflows/.*\.yaml
8484
_release_template_file.md
8585
ignore$
86+
ipinfo

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ providers/build: \
198198
providers/build/network \
199199
providers/build/os \
200200
providers/build/ipmi \
201+
providers/build/ipinfo \
201202
providers/build/oci \
202203
providers/build/slack \
203204
providers/build/github \
@@ -231,6 +232,7 @@ providers/install: \
231232
providers/install/network \
232233
providers/install/os \
233234
providers/install/ipmi \
235+
providers/install/ipinfo \
234236
providers/install/oci \
235237
providers/install/slack \
236238
providers/install/github \
@@ -409,10 +411,16 @@ providers/build/tailscale: providers/lr
409411
providers/install/tailscale:
410412
@$(call installProvider, providers/tailscale)
411413

414+
providers/build/ipinfo: providers/lr
415+
@$(call buildProvider, providers/ipinfo)
416+
providers/install/ipinfo:
417+
@$(call installProvider, providers/ipinfo)
418+
412419
providers/dist:
413420
@$(call buildProviderDist, providers/network)
414421
@$(call buildProviderDist, providers/os)
415422
@$(call buildProviderDist, providers/ipmi)
423+
@$(call buildProviderDist, providers/ipinfo)
416424
@$(call buildProviderDist, providers/oci)
417425
@$(call buildProviderDist, providers/slack)
418426
@$(call buildProviderDist, providers/github)
@@ -443,6 +451,7 @@ providers/bundle:
443451
@$(call bundleProvider, providers/network)
444452
@$(call bundleProvider, providers/os)
445453
@$(call bundleProvider, providers/ipmi)
454+
@$(call bundleProvider, providers/ipinfo)
446455
@$(call bundleProvider, providers/oci)
447456
@$(call bundleProvider, providers/slack)
448457
@$(call bundleProvider, providers/github)
@@ -474,6 +483,7 @@ providers/test:
474483
@$(call testProvider, providers/network)
475484
@$(call testProvider, providers/os)
476485
@$(call testGoModProvider, providers/ipmi)
486+
@$(call testGoModProvider, providers/ipinfo)
477487
@$(call testGoModProvider, providers/oci)
478488
@$(call testGoModProvider, providers/slack)
479489
@$(call testGoModProvider, providers/github)
@@ -582,6 +592,11 @@ lr/docs/markdown: providers/lr
582592
--description "The IPMI resource pack lets you use MQL to query and assess the security of your IPMI devices." \
583593
--docs-file providers/ipmi/resources/ipmi.lr.manifest.yaml \
584594
--output ../docs/docs/mql/resources/ipmi-pack
595+
./lr markdown providers/ipinfo/resources/ipinfo.lr \
596+
--pack-name "IPinfo" \
597+
--description "The IPinfo resource pack lets you use MQL to query IP address information from ipinfo.io." \
598+
--docs-file providers/ipinfo/resources/ipinfo.lr.manifest.yaml \
599+
--output ../docs/docs/mql/resources/ipinfo-pack
585600
./lr markdown providers/k8s/resources/k8s.lr \
586601
--pack-name "Kubernetes (K8s)" \
587602
--description "The Kubernetes resource pack lets you use MQL to query and assess the security of your Kubernetes clusters and workloads." \

providers/defaults.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,4 +552,18 @@ var DefaultProviders Providers = map[string]*Provider{
552552
},
553553
},
554554
},
555+
"ipinfo": {
556+
Provider: &plugin.Provider{
557+
Name: "ipinfo",
558+
ID: "go.mondoo.com/cnquery/providers/ipinfo",
559+
ConnectionTypes: []string{"ipinfo"},
560+
Connectors: []plugin.Connector{
561+
{
562+
Name: "ipinfo",
563+
Use: "ipinfo",
564+
Short: "Query ipinfo.io for IP address information",
565+
},
566+
},
567+
},
568+
},
555569
}

providers/ipinfo/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# IPinfo Provider
2+
3+
```shell
4+
cnquery shell ipinfo
5+
```
6+
7+
For authentication, you can use the `IPINFO_TOKEN` environment variable.
8+
9+
```shell
10+
export IPINFO_TOKEN="<token>"
11+
```
12+
13+
## Examples
14+
15+
**Query IP information**
16+
17+
Query information for a specific IP address.
18+
19+
```shell
20+
cnquery> ipinfo(ip("8.8.8.8")) { * }
21+
ipinfo: {
22+
requested_ip: "8.8.8.8"
23+
returned_ip: "8.8.8.8"
24+
hostname: "dns.google"
25+
bogon: false
26+
}
27+
```
28+
29+
**Query your public IP**
30+
31+
Query information for your machine's public IP address.
32+
33+
```shell
34+
cnquery> ipinfo() { * }
35+
ipinfo: {
36+
requested_ip: null
37+
returned_ip: "<your-public-ip>"
38+
hostname: "<hostname>"
39+
bogon: false
40+
}
41+
```
42+
43+
**Query IP information from network interfaces**
44+
45+
Query IP information for all IPs from network interfaces.
46+
47+
```shell
48+
cnquery run -c "network.interfaces.map(ips.map(_.ip)).flat.map(ipinfo(_){*})"
49+
network.interfaces.map.flat.map: [
50+
0: {
51+
returned_ip: 127.0.0.1
52+
hostname: ""
53+
bogon: true
54+
requested_ip: 127.0.0.1
55+
}
56+
......
57+
58+
```

providers/ipinfo/config/config.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Mondoo, Inc.
2+
// SPDX-License-Identifier: BUSL-1.1
3+
4+
package config
5+
6+
import (
7+
"go.mondoo.com/cnquery/v12/providers-sdk/v1/plugin"
8+
"go.mondoo.com/cnquery/v12/providers/ipinfo/provider"
9+
)
10+
11+
var Config = plugin.Provider{
12+
Name: "ipinfo",
13+
ID: "go.mondoo.com/cnquery/providers/ipinfo",
14+
Version: "12.10.0",
15+
ConnectionTypes: []string{provider.DefaultConnectionType},
16+
Connectors: []plugin.Connector{
17+
{
18+
Name: "ipinfo",
19+
Use: "ipinfo",
20+
Short: "Query ipinfo.io for IP address information",
21+
Long: `Use the ipinfo provider to query IP address information from ipinfo.io, including the IP address, hostname, and whether the IP address is a bogon.
22+
23+
Examples:
24+
cnquery shell ipinfo
25+
cnquery run ipinfo -c "ipinfo(ip('8.8.8.8')){*}"
26+
cnquery run ipinfo -c "ipinfo(){*}" # Query your public IP"
27+
cnquery run -c "network.interfaces.map(ips.map(_.ip)).flat.map(ipinfo(_){*})"
28+
29+
Notes:
30+
- Pass an IP address to query information about that specific IP: ipinfo(ip("1.1.1.1"))
31+
- Pass no arguments (empty IP) to query your machine's public IP: ipinfo()
32+
- The bogon field indicates whether the returned IP is a private, link-local, or otherwise non-routable address. When bogon is true, the returned IP is the same as the requested IP.
33+
- Set IPINFO_TOKEN environment variable to use the authenticated ipinfo.io API.
34+
`,
35+
Discovery: []string{},
36+
Flags: []plugin.Flag{},
37+
},
38+
},
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Mondoo, Inc.
2+
// SPDX-License-Identifier: BUSL-1.1
3+
4+
package connection
5+
6+
import (
7+
"os"
8+
9+
"go.mondoo.com/cnquery/v12/providers-sdk/v1/inventory"
10+
"go.mondoo.com/cnquery/v12/providers-sdk/v1/plugin"
11+
)
12+
13+
type IpinfoConnection struct {
14+
plugin.Connection
15+
Conf *inventory.Config
16+
asset *inventory.Asset
17+
token string
18+
client interface{} // ipinfo client will be stored here
19+
}
20+
21+
func NewIpinfoConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*IpinfoConnection, error) {
22+
conn := &IpinfoConnection{
23+
Connection: plugin.NewConnection(id, asset),
24+
Conf: conf,
25+
asset: asset,
26+
}
27+
28+
conn.token = os.Getenv("IPINFO_TOKEN")
29+
30+
return conn, nil
31+
}
32+
33+
func (c *IpinfoConnection) Name() string {
34+
return "ipinfo"
35+
}
36+
37+
func (c *IpinfoConnection) Asset() *inventory.Asset {
38+
return c.asset
39+
}
40+
41+
func (c *IpinfoConnection) Client() interface{} {
42+
return c.client
43+
}
44+
45+
func (c *IpinfoConnection) SetClient(client interface{}) {
46+
c.client = client
47+
}
48+
49+
func (c *IpinfoConnection) Token() string {
50+
return c.token
51+
}

providers/ipinfo/gen/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Mondoo, Inc.
2+
// SPDX-License-Identifier: BUSL-1.1
3+
4+
package main
5+
6+
import (
7+
"go.mondoo.com/cnquery/v12/providers-sdk/v1/plugin/gen"
8+
"go.mondoo.com/cnquery/v12/providers/ipinfo/config"
9+
)
10+
11+
func main() {
12+
gen.CLI(&config.Config)
13+
}

0 commit comments

Comments
 (0)