Posted On November 22, 2022

Use PowerShell to Get GeoLocation of a Computer’s Public IP

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Use PowerShell to Get GeoLocation of a Computer’s Public IP

Method 1:

Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content)

Method 2:

function getIPGeolocation($ipAddress) {

$request = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$ipAddress"

[PSCustomObject]@{
IP = $request.query
City = $request.city
Country = $request.country
Isp = $request.isp
}
}

$thisPublicIP=(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
getIPGeolocation $thisPublicIP

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Generate Report of Users and Computers That Have Not Logged On for X Days

# AccountsNotLoginXDays.ps1# Set days$lastLogonDaysExceeding = 120# Gather Users$daysRange = (get-date).adddays(-$lastLogonDaysExceeding)$users=Get-ADUser -properties * -filter {(enabled -eq…

PowerShell: Automating Dynamics CRM Migration

This is the source code that has been used to move hundreds of Dynamics CRM…

match

- The match() method retrieves the matches when matching a string against a regular expression.…