To start working with Shodan you have to get your token first. You can do this at https://www.shodan.io.
The import path depends on whether you use go modules:
import "github.com/ns3777k/go-shodan/v4/shodan" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/ns3777k/go-shodan/shodan" // with go modules disabled
Simple example of resolving hostnames:
package main
import (
"log"
"context"
"github.com/ns3777k/go-shodan/v4/shodan" // go modules required
)
func main() {
client := shodan.NewEnvClient(nil)
dns, err := client.GetDNSResolve(context.Background(), []string{"google.com", "ya.ru"})
if err != nil {
log.Panic(err)
} else {
log.Println(dns["google.com"])
}
}
Output for above:
2015/09/05 18:50:52 173.194.115.35
Streaming example:
package main
import (
"log"
"context"
"github.com/ns3777k/go-shodan/v4/shodan" // go modules required
)
func main() {
client := shodan.NewEnvClient(nil)
ch := make(chan *shodan.HostData)
err := client.GetBannersByASN(context.Background(), []string{"3303", "32475"}, ch)
if err != nil {
panic(err)
}
for {
banner, ok := <-ch
if !ok {
log.Println("channel was closed")
break
}
log.Println(banner.Product)
}
}
Every method accepts context in the first argument so you can easily cancel any request.
You can also use SetDebug(true)
to see the actual request data (method, url, body).
- /shodan/host/{ip}
- /shodan/host/count
- /shodan/host/search
- /shodan/host/search/facets
- /shodan/host/search/filters
- /shodan/host/search/tokens
- /shodan/ports
- /shodan/protocols
- /shodan/scan
- /shodan/scan/internet
- /shodan/scan/{id}
- /shodan/alert
- /shodan/alert/{id}/info
- /shodan/alert/{id}
- /shodan/alert/info
- /shodan/alert/triggers
- /shodan/alert/{id}/notifier/{notifier_id}
- /shodan/alert/{id}/trigger/{trigger}
- /shodan/alert/{id}/trigger/{trigger}/ignore/{service}
- /notifier
- /notifier/provider
- /notifier/{id}
- /shodan/query
- /shodan/query/search
- /shodan/query/tags
- /account/profile
- /dns/resolve
- /dns/reverse
- /dns/domain/{domain}
- /shodan/data
- /shodan/data/{dataset}
- /org
- /org/member/{user}
- /tools/httpheaders
- /tools/myip
- /api-info
- /labs/honeyscore/{ip}
- /search
- /count
- /shodan/banners
- /shodan/asn/{asn}
- /shodan/countries/{countries}
- /shodan/ports/{ports}
- /shodan/alert
- /shodan/alert/{id}
- /api/ping/{ip}
- /api/geoping/{ip}
- /api/dns/{hostname}
- /api/geodns/{hostname}
If a method is absent or something doesn't work properly don't hesitate to create an issue.