+package main
+
+import (
+ "encoding/json"
+ "flag"
+ "fmt"
+ "net/http"
+)
+type Status struct {
+ Continent string `json:"continent"`
+ Country string `json:"country"`
+ Region string `json:"region"`
+ City string `json:"city"`
+ Zip string `json:"zip"`
+ Latitude string `json:"lat"`
+ Longitude string `json:"lon"`
+ Timezone string `json:"timezone"`
+ Query string `json:"query"`
+}
+const (
+ url = "http://ip-api.com"
+)
+var (
+ ip_addr string
+)
+func init() {
+ flag.StringVar(&ip_addr, "i", "1.1.1.1", "IP address to check")
+}
+func main() {
+ flag.Parse()
+
+ if len(ip_addr) == 0 {
+ fmt.Println("No IP address given, trying default")
+ }
+
+ var status Status
+ query_url := url + "/" + ip_addr
+ resp, err := http.Get(query_url)
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer resp.Body.Close()
+ _ = json.NewDecoder(resp.Body).Decode(&status)
+ fmt.Printf("Continent: %v\nCountry: %v\nRegion: %v\nCity: %v\nZip: %v\nLatitude: %v\nLongitude: %v\nTimezone: %v\nQuery: %v\n", status.Continent, status.Country, status.Region, status.City, status.Zip, status.Latitude, status.Longitude, status.Timezone, status.Query)
+}