diff --git a/Dockerfile b/Dockerfile index 193c40d..9a71bbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,12 @@ RUN sed 's/GeoLite2-Country_[0-9]*.tar.gz/GeoLite2-Country.tar.gz/g' -i GeoLite2 RUN sha256sum -c GeoLite2-Country.tar.gz.sha256 RUN tar xvf GeoLite2-Country.tar.gz --strip 1 +RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz +RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 +RUN sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256 +RUN sha256sum -c GeoLite2-City.tar.gz.sha256 +RUN tar xvf GeoLite2-City.tar.gz --strip 1 + FROM alpine:3.19 as release LABEL name="ipinfo.tw" RUN mkdir -p /run/nginx/ /usr/share/GeoIP/ diff --git a/README.md b/README.md index 5858d61..bd7b3e4 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,12 @@ Use any http(s) client to explore the server, e.g. https://ipinfo.tw, - `wget -qO- https://ipinfo.tw` - `curl https://ipinfo.tw` -Without any specified URI, the server will return IP address, country, AS, and user agent. +Without any specified URI, the server will return IP address, country, timezone, AS, and user agent. If you prefer to receive a machine-readable result, use path `/json` (without trailing slash), e.g. `https://ipinfo.tw/json`, the result will look like: ```json -{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"} +{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","timezone":"Asia/Tokyo","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"} ``` #### Endpoints @@ -75,6 +75,7 @@ You can also specify the following URI to retrieve certain info: - `asn`: AS number - `as_desc`: AS description - `user_agent`: User agent string +- `timezone`: Timezone based on the city (e.g Europe/Amsterdam) Examples: @@ -97,6 +98,9 @@ HK $ curl https://ipinfo.tw/country_name South Korea +$ curl https://ipinfo.tw/timezone +Europe/Amsterdam + $ curl https://ipinfo.tw/as AS16509 / Amazon.com, Inc. diff --git a/nginx/conf.d/geoip2.conf b/nginx/conf.d/geoip2.conf index 50051de..630fbd8 100644 --- a/nginx/conf.d/geoip2.conf +++ b/nginx/conf.d/geoip2.conf @@ -11,3 +11,8 @@ geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb { $ip_aso source=$remote_addr autonomous_system_organization; $ip_as_build_epoch metadata build_epoch; } + +geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb { + auto_reload 1d; + $ip_time_zone source=$remote_addr location time_zone; +} diff --git a/nginx/conf.d/ipinfo.conf b/nginx/conf.d/ipinfo.conf index a21c46e..7eee71d 100644 --- a/nginx/conf.d/ipinfo.conf +++ b/nginx/conf.d/ipinfo.conf @@ -50,6 +50,9 @@ server { location = /user_agent { return 200 "$http_user_agent\n"; } + location = /timezone { + return 200 "$ip_time_zone\n"; + } location ~* ^/index.htm(l)?$ { rewrite ^(.*)$ /; } @@ -58,7 +61,7 @@ server { } location = /json { default_type application/json; - return 200 "{\"ip\":\"$remote_addr\",\"country_code\":\"$ip_country_code\",\"country_name\":\"$ip_country_name\",\"asn\":\"$ip_asn\",\"as_desc\":\"$ip_aso\",\"user_agent\":\"$http_user_agent\"}\n"; + return 200 "{\"ip\":\"$remote_addr\",\"country_code\":\"$ip_country_code\",\"country_name\":\"$ip_country_name\",\"timezone\":\"$ip_time_zone\",\"asn\":\"$ip_asn\",\"as_desc\":\"$ip_aso\",\"user_agent\":\"$http_user_agent\"}\n"; } location = /build_epoch { default_type application/json;