echoip/README.md

131 lines
2.8 KiB
Markdown
Raw Normal View History

2018-08-27 20:33:29 +02:00
# echoip
2012-11-19 19:11:03 +01:00
2018-08-27 20:33:29 +02:00
[![Build Status](https://travis-ci.org/mpolden/echoip.svg)](https://travis-ci.org/mpolden/echoip)
2015-09-17 21:31:14 +02:00
2012-11-19 19:11:03 +01:00
A simple service for looking up your IP address. This is the code that powers
2018-03-21 22:04:53 +01:00
https://ifconfig.co.
2012-11-19 19:11:03 +01:00
2015-09-17 21:14:09 +02:00
## Usage
2012-11-21 13:58:06 +01:00
2015-09-17 21:14:09 +02:00
Just the business, please:
2012-11-21 13:58:06 +01:00
2015-09-17 21:14:09 +02:00
```
$ curl ifconfig.co
127.0.0.1
2016-04-15 20:57:35 +02:00
$ http ifconfig.co
2015-09-17 21:14:09 +02:00
127.0.0.1
2016-04-15 20:57:35 +02:00
$ wget -qO- ifconfig.co
127.0.0.1
2018-03-21 22:04:53 +01:00
$ fetch -qo- https://ifconfig.co
2015-09-17 21:14:09 +02:00
127.0.0.1
$ bat -print=b ifconfig.co/ip
127.0.0.1
2015-09-17 21:14:09 +02:00
```
2016-04-17 11:52:37 +02:00
Country and city lookup:
2015-09-17 21:14:09 +02:00
```
2018-03-21 22:04:53 +01:00
$ curl ifconfig.co/country
2016-04-17 11:52:37 +02:00
Elbonia
2018-03-21 22:04:53 +01:00
$ curl ifconfig.co/country-iso
2018-02-09 20:41:30 +01:00
EB
2018-03-21 22:04:53 +01:00
$ curl ifconfig.co/city
2016-04-17 11:52:37 +02:00
Bornyasherk
2019-07-05 15:01:45 +02:00
$ curl ifconfig.co/asn
AS59795
2015-09-17 21:14:09 +02:00
```
As JSON:
```
2018-03-21 22:04:53 +01:00
$ curl -H 'Accept: application/json' ifconfig.co # or curl ifconfig.co/json
2015-09-17 21:14:09 +02:00
{
2016-04-17 11:52:37 +02:00
"city": "Bornyasherk",
"country": "Elbonia",
2018-02-09 20:41:30 +01:00
"country_iso": "EB",
2016-07-06 23:44:33 +02:00
"ip": "127.0.0.1",
2019-07-05 15:01:45 +02:00
"ip_decimal": 2130706433,
"asn": "AS59795",
"asn_org": "Hosting4Real"
2015-09-17 21:14:09 +02:00
}
```
2012-11-19 19:11:03 +01:00
2018-03-21 22:04:53 +01:00
Port testing:
```
$ curl ifconfig.co/port/80
{
"ip": "127.0.0.1",
"port": 80,
"reachable": false
}
```
Pass the appropriate flag (usually `-4` and `-6`) to your client to switch
between IPv4 and IPv6 lookup.
2015-09-17 21:14:09 +02:00
## Features
2012-11-19 19:11:03 +01:00
* Easy to remember domain name
2018-03-21 22:04:53 +01:00
* Fast
* Supports IPv6
2016-04-15 20:57:35 +02:00
* Supports HTTPS
2018-03-21 22:04:53 +01:00
* Supports common command-line clients (e.g. `curl`, `httpie`, `wget` and `fetch`)
* JSON output
2019-07-05 15:01:45 +02:00
* ASN, country and city lookup using the MaxMind GeoIP database
2018-03-21 22:04:53 +01:00
* Port testing
* All endpoints (except `/port`) can return information about a custom IP address specified via `?ip=` query parameter
2016-04-15 20:57:35 +02:00
* Open source under the [BSD 3-Clause license](https://opensource.org/licenses/BSD-3-Clause)
2015-09-17 21:14:09 +02:00
## Why?
2012-11-19 19:11:03 +01:00
* To scratch an itch
* An excuse to use Go for something
* Faster than ifconfig.me and has IPv6 support
2015-09-17 21:14:09 +02:00
## Building
Compiling requires the [Golang compiler](https://golang.org/) to be installed.
2018-03-21 22:04:53 +01:00
This package can be installed with `go get`:
2015-09-17 21:14:09 +02:00
2018-08-27 20:33:29 +02:00
`go get github.com/mpolden/echoip/...`
2015-09-17 21:14:09 +02:00
2017-11-29 19:29:26 +01:00
For more information on building a Go project, see the [official Go
documentation](https://golang.org/doc/code.html).
2018-12-28 15:06:52 +01:00
## Docker image
A Docker image is available on [Docker
Hub](https://hub.docker.com/r/mpolden/echoip), which can be downloaded with:
`docker pull mpolden/echoip`
2015-09-17 21:14:09 +02:00
### Usage
```
2018-08-27 20:33:29 +02:00
$ echoip -h
2015-09-17 21:14:09 +02:00
Usage:
2018-08-27 20:33:29 +02:00
echoip [OPTIONS]
2015-09-17 21:14:09 +02:00
Application Options:
2018-03-21 22:04:53 +01:00
-f, --country-db=FILE Path to GeoIP country database
-c, --city-db=FILE Path to GeoIP city database
2019-07-05 15:01:45 +02:00
-a, --asn-db=FILE Path to GeoIP ASN database
2018-03-21 22:04:53 +01:00
-l, --listen=ADDR Listening address (default: :8080)
-r, --reverse-lookup Perform reverse hostname lookups
-p, --port-lookup Enable port lookup
-t, --template=FILE Path to template (default: index.html)
-H, --trusted-header=NAME Header to trust for remote IP, if present (e.g. X-Real-IP)
-C, --cache-size=SIZE Size of response cache. Set to 0 to disable
2015-09-17 21:14:09 +02:00
Help Options:
2018-03-21 22:04:53 +01:00
-h, --help Show this help message
2015-09-17 21:14:09 +02:00
```