skip to Main Content

The title might seem a bit odd, but I have a situation where I have a web application (Node.js application served up behind Azure Frontdoor + Azure App Service) and need to know if a request has come from Scotland, so that I can show some specific assets (mostly images) to the user in place of the default ones.

I was hoping to do this programmatically, leveraging Frontdoor’s capabilities to inject something into the request coming into App Service and then checking the header in my Node.js application and decide what assets to load that way.

However, Frontdoor will only tell me if a request originated in the United Kingdom. I’ve also looked at a few libraries/APIs and nothing seems to be that granular. I’ve also tried looking up if there is a canonical list of IP ranges within Scotland, but that (expectedly) turned up nothing.

I know this problem could be solved with a UX change (i.e. asking someone at the beginning of their journey where they reside) but was hoping to make things slightly more seamless.

Any suggestions would be appreciated.

2

Answers


  1. You could use a service like https://ipinfo.io/ it has an IP Geolocation API.

    You can get the user IP in the header X-Azure-ClientIP from Frontdoor and then make an API call to get the region. Furthermore, you should link that information to a user for persistence you won’t have to make an API call every time a user access your website.

    Example IP information from Scotland

    Login or Signup to reply.
  2. Disclaimer — I’m not associated with IPinfo in any way, I just use its API myself.


    As Lauden mentioned in his answer, the IP Geolocation API of IPinfo is a convenient choice. For a low number of batch requests — something like 100-150 subsequent ones for the same requesting IP — the service is free, for more professional use there are paid models.

    For example you can check on the region using curl as follows:

    curl -s https://ipapi.co/$IP/region
    

    Than you’ll get e.g.

    $ curl -s https://ipapi.co/84.64.83.219/region
    Scotland
    $ curl -s https://ipapi.co/82.37.113.61/region
    Scotland
    

    If you replace region and check on the parameter city, the first one yields Glasgow, the second one Edinburgh.

    The full dataset for 84.64.83.219 (Glasgow), when using free access to the API:

    $ curl -s https://ipapi.co/84.64.83.219/json
    {
        "ip": "84.64.83.219",
        "network": "84.64.82.0/23",
        "version": "IPv4",
        "city": "Glasgow",
        "region": "Scotland",
        "region_code": "SCT",
        "country": "GB",
        "country_name": "United Kingdom",
        "country_code": "GB",
        "country_code_iso3": "GBR",
        "country_capital": "London",
        "country_tld": ".uk",
        "continent_code": "EU",
        "in_eu": false,
        "postal": "G68",
        "latitude": 55.9555,
        "longitude": -4.0105,
        "timezone": "Europe/London",
        "utc_offset": "+0000",
        "country_calling_code": "+44",
        "currency": "GBP",
        "currency_name": "Pound",
        "languages": "en-GB,cy-GB,gd",
        "country_area": 244820.0,
        "country_population": 66488991,
        "asn": "AS5378",
        "org": "Vodafone Limited"
    }
    

    And, to the last, IPinfo also provides an Official Command Line Interface for its APIs, supporting Linux (Debian, Ubuntu, Arch), FreeBSD, and even obscure operating systems like Windows and MacOS.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search