PowerShell.com recently published a tip, Identifying Origin of IP Address, that allows you to get the country of an IP Address. Seeing how this was built I decide to write a similar function that gathers a bit more information. The function provides information about the IP,Country,City and actual Latitude and Longtitude of an IP Address as provided by http://freegeoip.net.
Function Get-GeoIP { param ( [string]$IP ) ([xml](Invoke-WebRequest "http://freegeoip.net/xml/$IP").Content).Response } |
The function takes an IP address as input and uses this to gather the results in XML-format from the freegeoip.net website. This output is then presented to PowerShell as an Xml element. The output can also be filtered using the Select-Object Cmdlet.