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: Get OU of a User & Get All Users In an OU

function getUserOu($username){ if(!(get-module activedirectory -ea SilentlyContinue)){ $osType=switch ((Get-CimInstance -ClassName Win32_OperatingSystem).ProductType){ 1 {'client'} 2 {'domaincontroller'} 3…

PowerShell: Taking a Snapshot of a Windows Volume

I have this snippet embedded in various programs. Perhaps, it's useful to be posted as…

PowerShell: Add Windows NTFS Permissions to File or Folder

The re-usable function: $path='C:\Windows\servicing' $accountsToAdd='Administrators' $permissions='Full' function addNtfsPermissions ($path,$accountsToAdd,$permissions){ $acl = Get-ACL $path $accessRule=New-Object System.Security.AccessControl.FileSystemAccessRule($accountsToAdd,$permissions,"Allow")…