-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (83 loc) · 2.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"io/ioutil"
"fmt"
"net/http"
"strings"
"encoding/json"
)
type ShodanResp struct {
RegionCode interface{} `json:"region_code"`
IP string `json:"ip"`
AreaCode interface{} `json:"area_code"`
CountryName string `json:"country_name"`
Hostnames []interface{} `json:"hostnames"`
PostalCode interface{} `json:"postal_code"`
DmaCode interface{} `json:"dma_code"`
CountryCode string `json:"country_code"`
Data []struct {
Product string `json:"product,omitempty"`
Os interface{} `json:"os"`
Timestamp string `json:"timestamp"`
Isp string `json:"isp"`
Asn string `json:"asn"`
Banner string `json:"banner"`
Hostnames []interface{} `json:"hostnames"`
Devicetype string `json:"devicetype,omitempty"`
Location struct {
City interface{} `json:"city"`
RegionCode interface{} `json:"region_code"`
AreaCode interface{} `json:"area_code"`
Longitude float64 `json:"longitude"`
CountryCode3 string `json:"country_code3"`
CountryName string `json:"country_name"`
PostalCode interface{} `json:"postal_code"`
DmaCode interface{} `json:"dma_code"`
CountryCode string `json:"country_code"`
Latitude float64 `json:"latitude"`
} `json:"location"`
IP string `json:"ip"`
Domains []interface{} `json:"domains"`
Org string `json:"org"`
Port int `json:"port"`
Opts struct {
} `json:"opts"`
} `json:"data"`
City interface{} `json:"city"`
Longitude float64 `json:"longitude"`
CountryCode3 string `json:"country_code3"`
Latitude float64 `json:"latitude"`
Os interface{} `json:"os"`
Ports []int `json:"ports"`
}
func apikey() (string) {
key, err := ioutil.ReadFile(".api_key")
if err != nil {
fmt.Print("No API Key found!")
}
return string(key)
}
func query() {
key := apikey()
ip := "121.42.98.22"
url := fmt.Sprintf("https://api.shodan.io/shodan/host/%s?key=%s", ip, key)
read_url := strings.TrimRight(url, "\r\n")
resp, err := http.Get(read_url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
//fmt.Println("Response Status: ", resp.Status)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var answ ShodanResp
json.Unmarshal(body, &answ)
fmt.Print(answ.Ports)
//fmt.Print(string(body))
}
func main() {
apikey()
query()
}