Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed Apr 28, 2018
0 parents commit f406d65
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Go "vendor" directory
vendor/

# Compiled binaries
ipinfo
ipinfo.exe

# Directory generated by GoReleaser
dist/
21 changes: 21 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
builds:
- binary: ipinfo
goos:
- windows
- darwin
- linux
goarch:
- amd64

archive:
files:
- README.md
- LICENSE.md
format_overrides:
- goos: windows
format: zip
replacements:
amd64: x86_64
386: x86
darwin: macos
wrap_in_directory: true
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

- Initial versioned release.
15 changes: 15 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright © 2018 Hugo Locurcio and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ipinfo

A command-line utility to retrieve your current IP address and related
information, or display information related to an IP address (such as
the country and Internet service provider).

## Usage

## License

Copyright © 2018 Hugo Locurcio and contributors

Unless otherwise specified, files in this repository are licensed under the
MIT license, see [LICENSE.md](LICENSE.md) for more information.
73 changes: 73 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ipinfo: Retrieve information about IP addresses
//
// Copyright © 2018 Hugo Locurcio and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package main

import (
"encoding/json"
"fmt"
"github.com/urfave/cli"
"log"
"net/http"
"os"
)

type IpInfo struct {
Ip string `json:"ip"` // IP address
Hostname string `json:"hostname"` // Hostname
City string `json:"city"` // City
Region string `json:"region"` // Region
Country string `json:"country"` // Country
Loc string `json:"loc"` // Location ("latitude,longitude" in degrees)
Postal string `json:"postal"` // Postal code
Org string `json:"org"` // Organization
}

func main() {
app := cli.NewApp()
app.Name = "ipinfo"
app.Version = "0.0.1"
app.Usage = "Retrieve information about IP addresses"
app.UsageText = app.Name + " [IP address]"

app.Action = func(c *cli.Context) error {
client := &http.Client{}
req, err := client.Get("http://ipinfo.io/json")

if err != nil {
fmt.Println("Error: Requesting IP address information failed.")
os.Exit(1)
}

defer req.Body.Close()
ipInfo := IpInfo{}
json.NewDecoder(req.Body).Decode(&ipInfo)

return nil
}

err := app.Run(os.Args)

if err != nil {
log.Fatal(err)
}
}

0 comments on commit f406d65

Please sign in to comment.