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:
yakumo.izuru 2023-10-09 23:13:18 +00:00
parent a9fc2a0a07
commit 1f1ceedda1
3 changed files with 60 additions and 2 deletions

View File

@ -1,10 +1,23 @@
![](https://raddle.me/submission_images/61e31cb98ba6f807847098560a6b29b2fbdf822069186d2cfe5fa67f747b13f2.gif) ![](https://raddle.me/submission_images/61e31cb98ba6f807847098560a6b29b2fbdf822069186d2cfe5fa67f747b13f2.gif)
# 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
View 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)
}