Get the most out of your Centmin Mod LEMP stack
Become a Member

Sysadmin Centmin Mod Geolocation IP Address Lookup Service Testing

Discussion in 'System Administration' started by eva2000, Apr 2, 2019.

Tags:
  1. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    There are various geolocation IP address lookup services online which return the IP addresses geographical location data. My most used is is ipinfo.io service. But @wmtech brought up a good point regarding privacy concerns with announcing your IP lookups to 3rd parties here.

    I've always wanted to host my own web/system admin tools for IP looks, dns tests myself but haven't really found the right scripts. So last night I setup 2 3 versions for geolocation IP address lookup services on a Centmin Mod LEMP stack powered server on a Upcloud.com KVM VPS :)

    Both versions can work via web browser as well as via SSH using curl with supported json output. However, version 1 can pass IPs on command as an argument, while version 2 can't and just detects IP of the user running the command. Updated: added 3rd version using native Centmin Mod 123.09beta01's Nginx with optional GeoIP2 Lite nginx module configured.
    Version 1 example SSH curl command json output fed into jq parser
    Code (Text):
    curl -s https://geoip.centminmod.com/json/8.8.8.8 | jq
    {
      "continent": {
        "code": "NA",
        "geoname_id": 6255149,
        "names": {
          "de": "Nordamerika",
          "en": "North America",
          "es": "Norteamérica",
          "fr": "Amérique du Nord",
          "ja": "北アメリカ",
          "pt-BR": "América do Norte",
          "ru": "Северная Америка",
          "zh-CN": "北美洲"
        }
      },
      "country": {
        "geoname_id": 6252001,
        "iso_code": "US",
        "names": {
          "de": "USA",
          "en": "United States",
          "es": "Estados Unidos",
          "fr": "États-Unis",
          "ja": "アメリカ合衆国",
          "pt-BR": "Estados Unidos",
          "ru": "США",
          "zh-CN": "美国"
        }
      },
      "geoip_DB_MTime": "Tue Apr  2 05:43:03 2019",
      "location": {
        "accuracy_radius": 1000,
        "latitude": 37.751,
        "longitude": -97.822
      },
      "registered_country": {
        "geoname_id": 6252001,
        "iso_code": "US",
        "names": {
          "de": "USA",
          "en": "United States",
          "es": "Estados Unidos",
          "fr": "États-Unis",
          "ja": "アメリカ合衆国",
          "pt-BR": "Estados Unidos",
          "ru": "США",
          "zh-CN": "美国"
        }
      },
      "traits": {
        "ip_address": "8.8.8.8"
      }
    }
    

    Version 2 example SSH curl command json output fed into jq parser. Useful just to detect the server's own public IP

    Will return IPv6 first if it exists. Change -s flag to -4s if you only want IPv4 address
    Code (Text):
    curl -s https://geoip.centminmod.com/ip/?json
    
    {
      "REMOTE_ADDR": "xxx.xxx.xxx.xxx",
      "IPCOUNTRY": "US",
      "HTTP_USER_AGENT": "curl/7.29.0"
    }
    

    Compared to ipinfo.io data which includes IP's ASN data which my versions don't support right now in the scripts.
    Code (Text):
    curl -s https://ipinfo.io/8.8.8.8
    {
      "ip": "8.8.8.8",
      "hostname": "google-public-dns-a.google.com",
      "city": "Mountain View",
      "region": "California",
      "country": "US",
      "loc": "37.3860,-122.0840",
      "postal": "94035",
      "phone": "650",
      "org": "AS15169 Google LLC"
    }
    


    Version 3 is pulling a head with native Centmin Mod 123.09beta01's Nginx with optional GeoIP2 Lite nginx mdoule configured and new GeoIP2 Lite ASN database added for ASN and Organisation data :D
    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/json/ | jq
    {
      "ip": "xxx.xxx.xxx.xxx",
      "asn": "25697",
      "org": "UpCloud USA Inc",
      "country code": "US",
      "country name": "United States",
      "region": "Illinois",
      "city": "",
      "postal code": "",
      "city continent code": "NA",
      "latitude": "41.84830",
      "longitude": "-87.65170",
      "country in eu": "",
      "location accuracy radius": "1000",
      "registered country code for IP": "US"
    }
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/ | jq
    {
      "ip": "xxx.xxx.xxx.xxx",
      "asn": "25697",
      "org": "UpCloud USA Inc",
      "country code": "US",
      "country name": "United States",
      "region": "Illinois",
      "city": "",
      "postal code": "",
      "city continent code": "NA",
      "latitude": "41.84830",
      "longitude": "-87.65170",
      "country in eu": "",
      "location accuracy radius": "1000",
      "registered country code for IP": "US"
    }
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/ | jq -r '.org'
    UpCloud USA Inc
    


    If folks have other suggestions for such geo IP scripts which also support json format output and passing IP addresses as arguments, please let me know :)

    @Matt @pamamolf @rdan @Jimmy @Sunka @bassie @BamaStangGuy @Revenge @deltahf @Xon if you folks have ideas too would be much appreciated :D
     
    Last edited: Apr 3, 2019
  2. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Examples

    looking up current server's public IPv4 address
    Code (Text):
    curl -4s https://geoip.centminmod.com/json/ | jq -r '.traits.ip_address'

    looking up current server's public IPv6 address
    Code (Text):
    curl -6s https://geoip.centminmod.com/json/ | jq -r '.traits.ip_address'

    server's public IP address's City
    Code (Text):
    curl -s https://geoip.centminmod.com/json/ | jq -r '.city.names'
    {
      "de": "Seattle",
      "en": "Seattle",
      "es": "Seattle",
      "fr": "Seattle",
      "ja": "シアトル",
      "pt-BR": "Seattle",
      "ru": "Сиэтл"
    }
    

    Code (Text):
    curl -s https://geoip.centminmod.com/json/ | jq -r '.city.names.en'
    Seattle
    

    country iso code
    Code (Text):
    curl -s https://geoip.centminmod.com/json/ | jq -r '.country.iso_code'
    US
    
     
  3. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  4. wmtech

    wmtech Active Member

    124
    37
    28
    Jul 22, 2017
    Ratings:
    +97
    Local Time:
    4:31 AM
  5. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  6. wmtech

    wmtech Active Member

    124
    37
    28
    Jul 22, 2017
    Ratings:
    +97
    Local Time:
    4:31 AM
    Just ignore the notice, they just want to sell their new API service.

    The script won't be updated any more, but works well and we can update it ourself, if the need ever arises. ;-)
     
  7. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    yeah figured they'd want to upsell :)

    Trying to find a version that provides GeoIP 2 ASN json/non-json lookup data too. Most of the up to date scripts only provide GeoIP 2 City database data but not ASN data.
     
  8. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Just updated Version 3 using native Centmin Mod 123.09beta01's Nginx with optional GeoIP2 Lite nginx mdoule configured with link to json output support. Out of the 3 versions, Version 3 benchmarked to perform the best at ~4x times faster than Version 1 and ~2x times faster than Version 2 :D
    Code (Text):
    curl -4s https://geoip.centminmod.com/ip1/json/ | jq
    {
      "ip": "XXX.XXX.XXX.XXX",
      "country code": "US",
      "country name": "United States",
      "region": "Illinois",
      "city": "",
      "postal code": "",
      "city continent code": "NA",
      "latitude": "41.84830",
      "longitude": "-87.65170",
      "country in eu": "",
      "location accuracy radius": "1000",
      "registered country code for IP": "US"
    }
    

    updated to also automatically switch to json output if wget or curl clients are detected on web url
    Code (Text):
    curl -4s https://geoip.centminmod.com/ip1/ | jq 
    {
      "ip": "XXX.XXX.XXX.XXX",
      "country code": "US",
      "country name": "United States",
      "region": "Illinois",
      "city": "",
      "postal code": "",
      "city continent code": "NA",
      "latitude": "41.84830",
      "longitude": "-87.65170",
      "country in eu": "",
      "location accuracy radius": "1000",
      "registered country code for IP": "US"
    }
    
     
  9. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Version 3 is pulling a head with native Centmin Mod 123.09beta01's Nginx with optional GeoIP2 Lite nginx mdoule configured and new GeoIP2 Lite ASN database added for ASN and Organisation data :D
    Code (Text):
    curl -4s https://geoip.centminmod.com/ip1/json/ | jq
    {
      "ip": "xxx.xxx.xxx.xxx",
      "asn": "25697",
      "org": "UpCloud USA Inc",
      "country code": "US",
      "country name": "United States",
      "region": "Illinois",
      "city": "",
      "postal code": "",
      "city continent code": "NA",
      "latitude": "41.84830",
      "longitude": "-87.65170",
      "country in eu": "",
      "location accuracy radius": "1000",
      "registered country code for IP": "US"
    }
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/ip1/ | jq
    {
      "ip": "xxx.xxx.xxx.xxx",
      "asn": "25697",
      "org": "UpCloud USA Inc",
      "country code": "US",
      "country name": "United States",
      "region": "Illinois",
      "city": "",
      "postal code": "",
      "city continent code": "NA",
      "latitude": "41.84830",
      "longitude": "-87.65170",
      "country in eu": "",
      "location accuracy radius": "1000",
      "registered country code for IP": "US"
    }
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/ip1/ | jq -r '.org'
    UpCloud USA Inc
    
     
  10. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  11. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  12. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    updated /v2 json curl output for json pretty formatting
    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/
    {
        "ip": "xxx.xxx.xxx.xxx",
        "asn": "25697",
        "org": "UpCloud USA Inc",
        "country code": "US",
        "country name": "United States",
        "region": "Illinois",
        "city": "",
        "timezone": "America/Chicago",
        "postal code": "",
        "city continent code": "NA",
        "latitude": "41.84830",
        "longitude": "-87.65170",
        "country in eu": "",
        "location accuracy radius": "1000",
        "registered country code": "US"
    }
    
     
  13. deltahf

    deltahf Premium Member Premium Member

    360
    170
    43
    Jun 8, 2014
    Ratings:
    +276
    Local Time:
    10:31 PM
  14. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  15. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    One last piece of the puzzle for https://geoip.centminmod.com/v2/ version is being able to lookup specific IP addresses and not just the visitor's IP. I added that via maxmind db reader php api but it's format and fields for json output differ when pulled from GeoIP 2 Lite City and ASN databases but still useful.

    lookup 66.249.84.62
    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/66.249.84.62

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/66.249.84.62
    {
        "ip": "66.249.84.62",
        "country": {
            "geoname_id": 6252001,
            "iso_code": "US",
            "names": {
                "de": "USA",
                "en": "United States",
                "es": "Estados Unidos",
                "fr": "États-Unis",
                "ja": "アメリカ合衆国",
                "pt-BR": "Estados Unidos",
                "ru": "США",
                "zh-CN": "美国"
            }
        },
        "location": {
            "accuracy_radius": 1000,
            "latitude": 37.751,
            "longitude": -97.822
        },
        "registered_country": {
            "geoname_id": 6252001,
            "iso_code": "US",
            "names": {
                "de": "USA",
                "en": "United States",
                "es": "Estados Unidos",
                "fr": "États-Unis",
                "ja": "アメリカ合衆国",
                "pt-BR": "Estados Unidos",
                "ru": "США",
                "zh-CN": "美国"
            }
        },
        "autonomous_system_number": 15169,
        "autonomous_system_organization": "Google LLC"
    }
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/66.249.84.62 | jq -r '.autonomous_system_organization'
    Google LLC
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/66.249.84.62 | jq -r '.country.iso_code'   
    US
    

    lookup 1.0.0.1
    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/1.0.0.1
    {
        "ip": "1.0.0.1",
        "city": {
            "geoname_id": 2070830,
            "names": {
                "en": "Glenelg",
                "ru": "Гленельг"
            }
        },
        "country": {
            "geoname_id": 2077456,
            "iso_code": "AU",
            "names": {
                "de": "Australien",
                "en": "Australia",
                "es": "Australia",
                "fr": "Australie",
                "ja": "オーストラリア",
                "pt-BR": "Austrália",
                "ru": "Австралия",
                "zh-CN": "澳大利亚"
            }
        },
        "location": {
            "accuracy_radius": 50,
            "latitude": -34.9808,
            "longitude": 138.515,
            "time_zone": "Australia/Adelaide"
        },
        "postal": {
            "code": 5045
        },
        "registered_country": {
            "geoname_id": 2077456,
            "iso_code": "AU",
            "names": {
                "de": "Australien",
                "en": "Australia",
                "es": "Australia",
                "fr": "Australie",
                "ja": "オーストラリア",
                "pt-BR": "Austrália",
                "ru": "Австралия",
                "zh-CN": "澳大利亚"
            }
        },
        "subdivisions": [
            {
                "geoname_id": 2061327,
                "iso_code": "SA",
                "names": {
                    "de": "Südaustralien",
                    "en": "South Australia",
                    "fr": "Australie-Méridionale",
                    "pt-BR": "Austrália Meridional",
                    "ru": "Южная Австралия"
                }
            }
        ],
        "autonomous_system_number": 13335,
        "autonomous_system_organization": "Cloudflare, Inc."
    }
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/1.0.0.1 | jq -r '.autonomous_system_organization'           
    National Internet Backbone
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/1.0.0.1 | jq -r '.country.iso_code'           
    AU
    

    Code (Text):
    curl -4s https://geoip.centminmod.com/v2/getip/1.0.0.1 | jq -r '.city.names.en'
    Glenelg
    
     
  16. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Added another GeoIP lookup version which is just purely JSON format output which most likely will end up being the version I use within Centmin Mod to do server geo lookups for so I can remove any 3rd party IP geo lookup services i.e. ipinfo.io from Centmin Mod :)
    Code (Text):
    curl -s https://geoip.centminmod.com/v3/ | jq -r '"country: \(.country) asn: \(.asn) org: \(.data.description_short)"'
    country: CA asn: 16276 org: OVH SAS
    
     
  17. rdan

    rdan Well-Known Member

    4,940
    1,180
    113
    May 25, 2014
    Ratings:
    +1,789
    Local Time:
    10:31 AM
    Mainline
    10.2
    This is very reliable service based on experience.
     
  18. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    12:31 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Yeah it is. The concern came up that some folks are worried about privacy of passing on IP info to 3rd parties like ipinfo.io. Hence, why I looked into offering my own in house Centmin Mod hosted IP geolocation data lookup tool :) The latest version v3 mentioned is backed by reliability of Cloudflare and uses Cloudflare's IP lookup database + ASN lookup lookup database :)
     
  19. rdan

    rdan Well-Known Member

    4,940
    1,180
    113
    May 25, 2014
    Ratings:
    +1,789
    Local Time:
    10:31 AM
    Mainline
    10.2
    Sometimes Cloudflare GEO is outdated compare to ipinfo database.