diff --git a/Makefile b/Makefile index 8f6eff6..a4ffc81 100644 --- a/Makefile +++ b/Makefile @@ -69,3 +69,6 @@ ifndef DEST_PATH endif rsync -a $(GOPATH)/bin/$(XBIN) $(DEST_PATH)/$(XBIN) @sha256sum $(GOPATH)/bin/$(XBIN) + +run: + go run cmd/echoip/main.go -a data/asn.mmdb -c data/city.mmdb -f data/country.mmdb -H x-forwarded-for -r diff --git a/README.md b/README.md index a74b6e4..1284fcb 100644 --- a/README.md +++ b/README.md @@ -127,5 +127,5 @@ Usage of echoip: -p Enable port lookup -r Perform reverse hostname lookups -t string - Path to template (default "index.html") + Path to template directory (default "html") ``` diff --git a/cmd/echoip/main.go b/cmd/echoip/main.go index 3d03634..cf98b76 100644 --- a/cmd/echoip/main.go +++ b/cmd/echoip/main.go @@ -36,7 +36,7 @@ func main() { listen := flag.String("l", ":8080", "Listening address") reverseLookup := flag.Bool("r", false, "Perform reverse hostname lookups") portLookup := flag.Bool("p", false, "Enable port lookup") - template := flag.String("t", "index.html", "Path to template") + template := flag.String("t", "html", "Path to template dir") cacheSize := flag.Int("C", 0, "Size of response cache. Set to 0 to disable") profile := flag.Bool("P", false, "Enables profiling handlers") var headers multiValueFlag diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..f32e3a5 --- /dev/null +++ b/html/index.html @@ -0,0 +1,320 @@ + + + + + What is my IP address? — {{ .Host }} + + + + + + + + {{ template "script.html" . }} {{ template "styles.html" . }} + + +
+
+
+

{{ .Hostname }} — What is my IP address?

+

{{ .IP }}

+

+ The best tool to find your own IP address, and information about it. +

+
+
+ +

+ This site is graciously hosted by
+ Leafcloud – The Truly Sustainable Cloud +

+
+
+ +
+ +
+
+

What do we know about this IP Adress?

+ + + + + + + + + + {{ if .Country }} + + + + + {{ end }} {{ if .CountryISO }} + + + + + {{ end }} {{ if .CountryEU }} + + + + + {{ end }} {{ if .RegionName }} + + + + + {{ end }} {{ if .RegionCode }} + + + + + {{ end }} {{ if .MetroCode }} + + + + + {{ end }} {{ if .PostalCode }} + + + + + {{ end }} {{ if .City }} + + + + + {{ end }} {{ if .Latitude }} + + + + + {{ end }} {{ if .Longitude }} + + + + + {{ end }} {{ if .Timezone }} + + + + + {{ end }} {{ if .ASN }} + + + + + {{ end }} {{ if .ASNOrg }} + + + + + {{ end }} {{ if .Hostname }} + + + + + {{ end }} {{ if .UserAgent }} {{ if .UserAgent.Comment }} + + + + + {{ end }} {{ if .UserAgent.Comment }} + + + + + {{ end }} {{ if .UserAgent.RawValue }} + + + + + {{ end }} {{ end }} +
IP Address{{ .IP }}
IP Decimal{{ .IPDecimal }}
Country{{ .Country }}
CountryISO{{ .CountryISO }}
CountryEU{{ .CountryEU }}
RegionName{{ .RegionName }}
RegionCode{{ .RegionCode }}
MetroCode{{ .MetroCode }}
PostalCode{{ .PostalCode }}
City{{ .City }}
Latitude{{ .Latitude }}
Longitude{{ .Longitude }}
Timezone{{ .Timezone }}
ASN{{ .ASN }}
ASNOrg{{ .ASNOrg }}
Hostname{{ .Hostname }}
User Agent{{ .UserAgent.Product }}/{{ .UserAgent.Version }}
Comment{{ .UserAgent.Comment }}
Raw Value{{ .UserAgent.RawValue }}
+

+ This information is provided from the GeoLite2 database created by + MaxMind, available from + www.maxmind.com +

+ + {{ if .City }} +
+

Map

+ +
+ {{ end }} +
+
+ +
+

How do I get this programmatically?

+

+ With the widget below you can build your query, and see what the + result will look like. +

+
+ +
+ + + + + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
You can open this page for another IP
+ + Check Another IP + + + +
+ And you can check if a port on your IP is open +
+ + Check For Port
+
+ + +
+

FAQ

+

How do I force IPv4 or IPv6 lookup?

+

+ As of 2018-07-25 it's no longer possible to force protocol using + the + v4 and v6 subdomains. IPv4 or IPv6 still can be + forced by passing the appropiate flag to your client, e.g + curl -4 or curl -6. +

+

Can I force getting JSON?

+

+ Setting the Accept: application/json header works as + expected. +

+ +

Is automated use of this service permitted?

+

+ Yes, as long as the rate limit is respected. The rate limit is in + place to ensure a fair service for all. +

+

+ Please limit automated requests to 1 request per minute. + No guarantee is made for requests that exceed this limit. They may + be rate-limited, with a 429 status code, or dropped entirely. +

+ +

Can I run my own service?

+

+ Yes, the source code and documentation is available on + GitHub. +

+
+
+
+
+ + diff --git a/html/leafcloud-logo.svg b/html/leafcloud-logo.svg new file mode 100644 index 0000000..9e9f4a7 --- /dev/null +++ b/html/leafcloud-logo.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/html/script.html b/html/script.html new file mode 100644 index 0000000..0d98614 --- /dev/null +++ b/html/script.html @@ -0,0 +1,105 @@ + diff --git a/html/styles.html b/html/styles.html new file mode 100644 index 0000000..a616aea --- /dev/null +++ b/html/styles.html @@ -0,0 +1,199 @@ + diff --git a/http/http.go b/http/http.go index 9545dc1..83c7f5d 100644 --- a/http/http.go +++ b/http/http.go @@ -321,7 +321,7 @@ func (s *Server) DefaultHandler(w http.ResponseWriter, r *http.Request) *appErro if err != nil { return internalServerError(err) } - t, err := template.ParseFiles(s.Template) + t, err := template.ParseGlob(s.Template + "/*") if err != nil { return internalServerError(err) } @@ -329,6 +329,7 @@ func (s *Server) DefaultHandler(w http.ResponseWriter, r *http.Request) *appErro if err != nil { return internalServerError(err) } + var data = struct { Response Host string diff --git a/index.html b/index.html deleted file mode 100644 index 8256fcd..0000000 --- a/index.html +++ /dev/null @@ -1,197 +0,0 @@ - - - - - What is my IP address? — {{ .Host }} - - - - - - - - -
-
-

What is my IP address?

-

{{ .IP }}

-

Multiple command line HTTP clients are supported, - including curl, httpie, httpie-go, GNU - Wget, fetch, and bat.

-

All endpoints, with the exception of /port, can return information about a custom IP address specified via ?ip= query parameter.

-
-
-
-
-

CLI examples

-
-$ curl {{ .Host }}
-{{ .IP }}
-
-$ http -b {{ .Host }}
-{{ .IP }}
-
-$ ht -b {{ .Host }}
-{{ .IP }}
-
-$ wget -qO- {{ .Host }}
-{{ .IP }}
-
-$ fetch -qo- http://{{ .Host }}
-{{ .IP }}
-
-$ bat -print=b {{ .Host }}/ip
-{{ .IP }}
-{{ if .Country }} -

Country lookup

-
-$ http {{ .Host }}/country
-{{ .Country }}
-
-$ http {{ .Host }}/country-iso
-{{ .CountryISO }}
-{{ end }} -{{ if .City }} -

City lookup

-
-$ http {{ .Host }}/city
-{{ .City }}
-{{ end }} -{{ if .ASN }} -

ASN lookup

-
-$ http {{ .Host }}/asn
-{{ .ASN }}
-{{ if .ASNOrg }}
-{{ end }} -{{ end }} -
-
-

JSON output

-
-$ http {{ .Host }}/json
-{{ .JSON }}
-

Setting the Accept: application/json header also works as expected.

-

Plain output

-

Always returns the IP address including a trailing newline, regardless of user agent.

-
-$ http {{ .Host }}/ip
-{{ .IP }}
-{{ if .Port }} -

Port testing

-
-$ http {{ .Host }}/port/8080
-{
-  "ip": "{{ .IP }}",
-  "port": 8080,
-  "reachable": false
-}
-{{ end }} -
-{{ if .City }} -
-

Map

- -
-{{ end }} -
-

FAQ

-

How do I force IPv4 or IPv6 lookup?

-

As of 2018-07-25 it's no longer possible to force protocol using - the v4 and v6 subdomains. IPv4 or IPv6 still can be forced - by passing the appropiate flag to your client, e.g curl -4 - or curl -6.

- -

Is automated use of this service permitted?

-

- Yes, as long as the rate limit is respected. The rate limit is in - place to ensure a fair service for all. -

-

- Please limit automated requests to 1 request per minute. No - guarantee is made for requests that exceed this limit. They may be - rate-limited, with a 429 status code, or dropped entirely. -

- -

Can I run my own service?

-

Yes, the source code and documentation is available on GitHub.

-
-
- - {{ if or .Country .City .ASN .ASNOrg }} -
- -
- {{ end }} - -