Skip to content

Instantly share code, notes, and snippets.

@yehgdotnet

yehgdotnet/shodan.go

Created Oct 13, 2020
Embed
What would you like to do?
golang shodan
package main
import (
"log"
//"os"
"context"
"github.com/ns3777k/go-shodan/shodan"
"fmt"
"flag"
"strings"
"time"
)
func arrayToString(a []int, delim string) string {
return strings.Trim(strings.Replace(fmt.Sprint(a), " ", delim, -1), "[]")
//return strings.Trim(strings.Join(strings.Split(fmt.Sprint(a), " "), delim), "[]")
//return strings.Trim(strings.Join(strings.Fields(fmt.Sprint(a)), delim), "[]")
}
func main() {
IPPtr := flag.String("ip", "1.1.1.1", "ip address")
flag.Parse()
//k := os.Getenv("SHODAN_KEY");
//fmt.Printf("using %s\n\nhost: %s\n\n",k,*IPPtr)
client := shodan.NewEnvClient(nil)
serviceopt := &shodan.HostServicesOptions{
History:false,
Minify:false,
}
hostInfo, err := client.GetServicesForHost(context.Background(), *IPPtr ,serviceopt)
if err != nil {
log.Panic(err)
} else {
fmt.Printf("host: %s , ports: %s\n",*IPPtr,arrayToString(hostInfo.Ports,","))
}
// shodan rate limiting 1s/req
time.Sleep(1 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment