/
wtfismyip.go
88 lines (69 loc) · 1.72 KB
/
wtfismyip.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"
"net/http"
"fmt"
"log"
"flag"
)
const wtfipurl = "https://wtfismyip.com/json"
type IPInfo struct {
YourFuckingIPAddress string
YourFuckingLocation string
YourFuckingHostname string
YourFuckingISP string
}
func main() {
var doAddr, doHost, doLoc, doISP, doAll, doNotCurse bool
var pref string
flag.BoolVar(&doAddr, "i", false, "Show my fucking IP Address")
flag.BoolVar(&doHost, "h", false, "Show my fucking Hostname")
flag.BoolVar(&doLoc, "l", false, "Show my fucking Location")
flag.BoolVar(&doISP, "p", false, "Show my fucking ISP")
flag.BoolVar(&doAll, "a", false, "Show me fucking Everything")
flag.BoolVar(&doNotCurse, "cursenot", false, "Fucking say fucking motherfucker")
flag.Parse()
client := &http.Client{}
req, err := http.NewRequest("GET", wtfipurl, nil)
if err != nil {
log.Fatalln(err)
}
req.Header.Add("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
ipinfo := IPInfo{}
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&ipinfo)
if err != nil {
log.Fatalln(err)
}
if !doAddr && !doHost && !doISP && !doLoc {
doAll = true
}
if doNotCurse {
pref = "Your"
} else {
pref = "Your Fucking"
}
if doAll {
fmt.Println(pref, "Addr:\t", ipinfo.YourFuckingIPAddress)
fmt.Println(pref, "Host:\t", ipinfo.YourFuckingHostname)
fmt.Println(pref, "ISP :\t", ipinfo.YourFuckingISP)
fmt.Println(pref, "Loc :\t", ipinfo.YourFuckingLocation)
return
}
if doAddr {
fmt.Println(ipinfo.YourFuckingIPAddress)
}
if doHost {
fmt.Println(ipinfo.YourFuckingHostname)
}
if doISP {
fmt.Println(ipinfo.YourFuckingISP)
}
if doLoc {
fmt.Println(ipinfo.YourFuckingLocation)
}
}