commit d50afa87e53b11f8706e440a100a4e530bb83429 Author: Luke Tainton Date: Sat Nov 21 17:45:44 2020 +0000 Inital commit 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)) +}