Change default to return self Public IP

This commit is contained in:
2021-11-16 22:56:02 -06:00
parent cc439eb7d4
commit cee1c30c63
3 changed files with 17 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ func main() {
utils.ParseFlags(&ip, &properties, &detail)
// Use the IP-API to lookup the IP address
data := ipapi.Lookup(ip)
data := ipapi.Lookup(&ip, &properties)
// Format the data to a string
result := ipapi.GetProperties(data, properties, detail)

View File

@@ -45,15 +45,24 @@ func buildURL(ip string) string {
// Get IP-API data about IP
//
// https://ip-api.com/docs/api:json
func Lookup(ip string) *IPAPI {
func Lookup(ip *string, properties *string) *IPAPI {
var data *IPAPI
if !utils.CheckValidIP(ip) {
utils.PrintOut("Invalid IP address")
utils.Exit(1)
}
if *ip == "" {
if *properties == "" {
*properties = "Query"
}
} else {
if *properties == "" {
*properties = "Country"
}
if !utils.CheckValidIP(*ip) {
utils.PrintOut("Invalid IP address during Lookup")
utils.Exit(1)
}
url := buildURL(ip)
}
url := buildURL(*ip)
resp, err := http.Get(url)
utils.HandleError(err)

View File

@@ -12,7 +12,7 @@ import (
// https://golang.org/pkg/flag/
func ParseFlags(ip *string, properties *string, detail *bool) {
flag.StringVar(ip, "ip", "", "IP address to lookup")
flag.StringVar(properties, "p", "Country", "Properties to retrieve")
flag.StringVar(properties, "p", "", "Properties to retrieve")
flag.BoolVar(detail, "d", false, "Show Detail")
flag.Parse()
}