Talk about a complete waste
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/mizuchi/trunk@3 383d55e2-5bb2-3e47-99b6-5684985ccae5
This commit is contained in:
parent
a9fc2a0a07
commit
1f1ceedda1
17
README.md
17
README.md
@ -1,10 +1,23 @@
|
|||||||

|

|
||||||
|
|
||||||
# mizuchi
|
# mizuchi
|
||||||
The above animated picture says it all.
|
The above animated picture says it all.
|
||||||
|
That aside, this was a full port from a shell script that I have never used seriously.
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
`go build -o mizuchi`
|
It has two flavors, and have slightly different output.
|
||||||
|
|
||||||
|
### For [ip-api.com](https://ip-api.com)
|
||||||
|
|
||||||
|
```
|
||||||
|
go build ./cmd/mizuchi-ipapi
|
||||||
|
```
|
||||||
|
|
||||||
|
### For [ipinfo.io](https://ipinfo.io)
|
||||||
|
|
||||||
|
```
|
||||||
|
go build ./cmd/mizuchi-ipinfo
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Only required argument is `-i`
|
Only required argument is `-i`
|
||||||
|
45
cmd/mizuchi-ipapi/main.go
Normal file
45
cmd/mizuchi-ipapi/main.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user