-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
87 lines (79 loc) · 2.2 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
package main
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
type IpInfo struct {
IP string `json:"ip"`
Hostname string `json:"hostname"`
City string `json:"city"`
Region string `json:"region"`
Country string `json:"country"`
Loc string `json:"loc"`
Postal string `json:"postal"`
Timezone string `json:"timezone"`
Asn struct {
Asn string `json:"asn"`
Name string `json:"name"`
Domain string `json:"domain"`
Route string `json:"route"`
Type string `json:"type"`
} `json:"asn"`
Company struct {
Name string `json:"name"`
Domain string `json:"domain"`
Type string `json:"type"`
} `json:"company"`
Privacy struct {
Vpn bool `json:"vpn"`
Proxy bool `json:"proxy"`
Tor bool `json:"tor"`
Hosting bool `json:"hosting"`
} `json:"privacy"`
Abuse struct {
Address string `json:"address"`
Country string `json:"country"`
Email string `json:"email"`
Name string `json:"name"`
Network string `json:"network"`
Phone string `json:"phone"`
} `json:"abuse"`
Domains struct {
IP string `json:"ip"`
Total int `json:"total"`
Domains []string `json:"domains"`
} `json:"domains"`
}
func main() {
var ipInfo IpInfo
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://ipinfo.io/widget", nil)
req.Header.Set("referer", "https://ipinfo.io/")
resp, _ := client.Do(req)
defer resp.Body.Close()
_ = json.NewDecoder(resp.Body).Decode(&ipInfo)
private := false
privacy := ""
privacyType := map[string]bool{
"vpn": ipInfo.Privacy.Vpn,
"tor": ipInfo.Privacy.Tor,
"proxy": ipInfo.Privacy.Proxy,
"hosting": ipInfo.Privacy.Hosting,
}
for k, v := range privacyType {
if v {
privacy += k + " "
private = true
}
}
if !private {
privacy = "none"
}
fmt.Printf("IP %s %s\n", ipInfo.IP, ipInfo.Hostname)
fmt.Printf("Geo %s %s, %s, %s %s\n", ipInfo.Loc, ipInfo.City, ipInfo.Region, ipInfo.Country, ipInfo.Postal)
fmt.Printf("ASN [%s %s: %s(%s)]\n", ipInfo.Asn.Asn, strings.ToUpper(ipInfo.Asn.Type), ipInfo.Asn.Name, ipInfo.Asn.Domain)
fmt.Printf("Company [%s: %s(%s)]\n", strings.ToUpper(ipInfo.Company.Type), ipInfo.Company.Name, ipInfo.Company.Domain)
fmt.Printf("Privacy %s\n", privacy)
}