This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
am-i-mole.go
137 lines (119 loc) · 3.21 KB
/
am-i-mole.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
)
type amIMole struct {
IP string `json:"ip"`
Country string `json:"country"`
City interface{} `json:"city"`
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
MullvadExitIP bool `json:"mullvad_exit_ip"`
MullvadExitIPHostname string `json:"mullvad_exit_ip_hostname"`
MullvadServerType string `json:"mullvad_server_type"`
Blacklisted struct {
Blacklisted bool `json:"blacklisted"`
Results []struct {
Name string `json:"name"`
Link string `json:"link"`
Blacklisted bool `json:"blacklisted"`
} `json:"results"`
} `json:"blacklisted"`
Organization string `json:"organization"`
}
func getJSON() amIMole {
resp, err := http.Get("https://am.i.mullvad.net/json")
if err != nil {
panic(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
amiMole := amIMole{}
json.Unmarshal(body, &amiMole)
return amiMole
}
func printFull(json amIMole) {
if json.MullvadExitIP == true {
fmt.Println("You ARE connected to Mullvad!")
fmt.Println("IP: ", json.IP)
fmt.Println("Exit IP Hostname: ", json.MullvadExitIPHostname)
fmt.Println("Server Type: ", json.MullvadServerType)
} else {
fmt.Println("You are NOT connected to Mullvad.")
fmt.Println("IP: ", json.IP)
}
fmt.Println("Country:", json.Country)
fmt.Println("City", json.City)
if json.Blacklisted.Blacklisted == true {
fmt.Println("Your IP IS blacklisted!")
for _, blacklist := range json.Blacklisted.Results {
fmt.Println(blacklist.Name, ": ", blacklist.Blacklisted)
fmt.Println(blacklist.Link)
}
} else {
fmt.Println("Your IP is NOT blacklisted!")
}
fmt.Println("Organisation: ", json.Organization)
}
func printIP(json amIMole) {
fmt.Println(json.IP)
}
func printConnected(json amIMole) {
fmt.Println(json.MullvadExitIP)
}
func printCountry(json amIMole) {
fmt.Println(json.Country)
}
func printCity(json amIMole) {
fmt.Println(json.City)
}
func printBlacklisted(json amIMole) {
fmt.Println(json.Blacklisted.Blacklisted)
if json.Blacklisted.Blacklisted == true {
for _, blacklist := range json.Blacklisted.Results {
fmt.Println(blacklist.Name, ": ", blacklist.Blacklisted)
fmt.Println(blacklist.Link)
}
}
}
func printOrganization(json amIMole) {
fmt.Println(json.Organization)
}
func main() {
ip := flag.Bool("ip", false, "Prints your current IP.")
conn := flag.Bool("c", false, "Prints if connected to mullvad.")
country := flag.Bool("ct", false, "Prints the country connected in.")
city := flag.Bool("cty", false, "Prints the city connected in.")
blacklist := flag.Bool("black", false, "Prints if blacklisted.")
organization := flag.Bool("o", false, "Prints the organization connecte to.")
flag.Parse()
json := getJSON()
if *ip == true {
printIP(json)
}
if *conn == true {
printConnected(json)
}
if *country == true {
printCountry(json)
}
if *city == true {
printCity(json)
}
if *blacklist == true {
printBlacklisted(json)
}
if *organization == true {
printOrganization(json)
}
if len(os.Args) == 1 {
printFull(json)
}
}