PowerShell/Scripts/locate-ipaddress.ps1

26 lines
596 B
PowerShell
Raw Normal View History

2020-12-29 15:14:21 +01:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
locate-ipaddress.ps1 [<IPaddress>]
.DESCRIPTION
Prints the geographic location of the given IP address
.EXAMPLE
PS> .\locate-ipaddress.ps1 177.144.67.98
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz / License: CC0
2020-12-29 15:14:21 +01:00
#>
2020-12-09 15:34:55 +01:00
2021-07-15 15:51:22 +02:00
param([string]$IPaddr = "")
2021-02-18 20:17:55 +01:00
2020-12-09 15:34:55 +01:00
try {
2021-07-15 15:51:22 +02:00
if ($IPaddr -eq "" ) { $IPaddr = read-host "Enter IP address to locate" }
2020-12-09 15:34:55 +01:00
$result = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IPaddr"
2020-12-25 11:30:43 +01:00
write-output $result
2020-12-09 15:34:55 +01:00
exit 0
} catch {
2021-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-09 15:34:55 +01:00
exit 1
}