go-shodan

To start working with Shodan you have to get your token first. You can do this at https://www.shodan.io.
Usage
The import path depends on whether you use go modules:
import "github.com/ns3777k/go-shodan/v4/shodan"
import "github.com/ns3777k/go-shodan/shodan"
Simple example of resolving hostnames:
package main
import (
"log"
"context"
"github.com/ns3777k/go-shodan/v4/shodan"
)
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"
)
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)
}
}
Tips and tricks
Every method accepts context in the first argument so you can easily cancel any request.
You can also use SetDebug(true) to see the curl version of your requests.
Implemented REST API
Search Methods
On-Demand Scanning
Network Alerts
Notifiers
Directory Methods
Account Methods
DNS Methods
Bulk Data
Manage Organization
Utility Methods
API Status Methods
Experimental Methods
Exploits
Implemented Streaming API
Data Streams
Network Alerts
If a method is absent or something doesn't work properly don't hesitate to create an issue.
Links