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: Add Office365 Records on DNS Servers

Make Changes to Internal DNS A. Delete Old CNAMES and MX Records Sample commands from…

PowerShell: Mount A Remote SMB/CIFS/NFS Share as a Specific User

This function is useful in scenarios where a separate user account is needed to mount…

PowerShell: Move Computer Objects in Active Directory

Version 2 # MoveComputers.ps1 # Version 0.0.2 # Obtain credentials being passed by Jenkins #…