Get-MdtWebsiteGeo -- Functionalizing Access to a Public API

Posted
Comments None

Beginning last year, the company I work for as begun blocking some web traffic by geographic IP. As an admin, there are all sorts of great resources hosted worldwide that I would like access to. While my friendly networking team is more than willing to help by adding necessary exceptions, I decided to write the following function so I could easily provide the relevant information when I suspect a resource is blocked.

The function uses the simple and useful freegeoip.net site which allows 15k anonymous calls per IP per hour. I cannot recall exactly why I set it to do a separate DNS lookup rather than calling the API by name instead of IP. I think doing it this way returned more data.

I might have goofed a little on the regex where it validates IPs to see that they’re external (I’m looking at you, 172.16.0.0\12) but it’s checked out in my testing so far. Honestly… it would just return blank data if a local IP gets through and you can always manually check any IPs that get warned out as internal.

There are a lot of little tasks like this that PowerShell is great at. I mean, look at that script above. If you’ve been using PowerShell for a year or more, and were pressed, you probably could have banged out a functional version in 5 minutes or less (15 minutes with the fiddly regex, which is an art unto itself). And then you could automate it into the background and move onto something else.

Author

Comments

There are currently no comments on this article.

Comment

Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.





← Older Newer →