From d50afa87e53b11f8706e440a100a4e530bb83429 Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Sat, 21 Nov 2020 17:45:44 +0000 Subject: [PATCH] Inital commit --- Main.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Main.go diff --git a/Main.go b/Main.go new file mode 100644 index 0000000..29c3fc7 --- /dev/null +++ b/Main.go @@ -0,0 +1,27 @@ +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "net/http" +) + +func getLocalIP() string { + resp, _ := http.Get("https://api.ipify.org") + // defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + return string(body[:]) +} + +func main() { + var ipaddress string + localIPAddress := getLocalIP() + flag.StringVar(&ipaddress, "i", localIPAddress, "Specify IP address. Defaults to current public IP address.") + flag.Parse() + apiEndpoint := "http://ip-api.com/json/" + ipaddress + resp, _ := http.Get(apiEndpoint) + // defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + fmt.Print(string(body)) +}