Category filter
Find the location of a Windows device using its IP address
Keeping track of the location and usage of company-owned devices is becoming increasingly important in today’s mobile and connected world. Having an eye on the type and location of the network that the employees who are working remotely is of utmost importance to reduce the risks of data breach and vulnerabilities. With Hexnode UEM, IT admins can now easily fetch the location, time zone, hostname, etc., of a Windows device using its IP address by executing custom scripts.
PowerShell script to find the location of a Windows device using its IP address
Use the following script to find the location of a Windows device using its IP address.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
$ip = (Test-Connection -ComputerName "google.com" -Count 1).IPV4Address.IPAddressToString $response = Invoke-RestMethod -Method Get -Uri "https://ipinfo.io/$ip/json" $ip = $response.ip $hostname = $response.hostname $city = $response.city $region = $response.region $country = $response.country $loc = $response.loc $org = $response.org $postal = $response.postal $timezone = $response.timezone Write-Output "IP: $ip" Write-Output "Hostname: $hostname" Write-Output "City: $city" Write-Output "Region: $region" Write-Output "Country: $country" Write-Output "Loc: $loc" Write-Output "Org: $org" Write-Output "Postal: $postal" Write-Output "Timezone: $timezone" |
Along with the IP address of your Windows device, the script fetches the following data.
- Hostname: displays the name by which the device identifies itself on the internet.
- City: displays the city where the device currently resides.
- Region: displays the state where the device resides.
- Country: displays the country in which the device resides.
- Loc: displays the latitude and longitude of the location where the device resides.
- Org: displays the name of the network operator to which the device is connected.
- Postal: displays the pin code of the location where the device resides.
- Time zone: displays the time zone of the location where the device resides.