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

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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
    • Like Like x 4
    • Winner Winner x 1
  2. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    • Like Like x 1
  4. wmtech

    wmtech Premium Member Premium Member

    122
    35
    28
    Jul 22, 2017
    Ratings:
    +93
    Local Time:
    7:15 AM
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  6. wmtech

    wmtech Premium Member Premium Member

    122
    35
    28
    Jul 22, 2017
    Ratings:
    +93
    Local Time:
    7:15 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

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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
    
     
    • Like Like x 1
  10. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  11. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  12. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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

    345
    163
    43
    Jun 8, 2014
    Ratings:
    +260
    Local Time:
    1:15 AM
  14. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    • Like Like x 1
  15. eva2000

    eva2000 Administrator Staff Member

    43,121
    9,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,115
    Local Time:
    4:15 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