Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d657329413 | |||
| c0d0fec86b | |||
| 7d8701768d | |||
| 55d2147a6c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
|||||||
bin/
|
bin/*
|
||||||
lookupip
|
lookupip
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
# lookupip
|
# lookupip
|
||||||
|
|
||||||
Simple go executable to task an ip and get the results from ip-api
|
Simple Go executable to query an IP and get the results from ip-api:
|
||||||
https://ip-api.com/
|
https://ip-api.com/
|
||||||
|
|
||||||
This is a fantastic site and I hope the continue to provide this
|
This is a fantastic site, and I hope they continue to provide this service.
|
||||||
|
|
||||||
Allows flag -p to replace the properties output
|
Allows flag -p to replace the properties output.
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
|
|||||||
@@ -63,21 +63,21 @@ func buildURL(ip string) (string, error) {
|
|||||||
// https://ip-api.com/docs/api:json
|
// https://ip-api.com/docs/api:json
|
||||||
func Lookup(ip string) (data IPAPI, err error) {
|
func Lookup(ip string) (data IPAPI, err error) {
|
||||||
|
|
||||||
url, error := buildURL(ip)
|
url, err := buildURL(ip)
|
||||||
if error != nil {
|
if err != nil {
|
||||||
return data, error
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if error != nil {
|
if err != nil {
|
||||||
return data, error
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&data)
|
err = json.NewDecoder(resp.Body).Decode(&data)
|
||||||
if error != nil {
|
if err != nil {
|
||||||
return data, error
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.Status == "fail" {
|
if data.Status == "fail" {
|
||||||
|
|||||||
Reference in New Issue
Block a user