Created
October 13, 2020 00:04
-
-
Save yehgdotnet/70fb0e44bfa75c43b2cc82544fe6468e to your computer and use it in GitHub Desktop.
golang shodan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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