From 0352894f9d42c2ee38ade9483d1c96d259087cf9 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 9 Dec 2020 14:34:55 +0000 Subject: [PATCH] Added locate-ipaddress.ps1 --- README.md | 1 + Scripts/locate-ipaddress.ps1 | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 Scripts/locate-ipaddress.ps1 diff --git a/README.md b/README.md index d23f61e5..91b0b385 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol * [list-cmdlets.ps1](Scripts/list-cmdlets.ps1) - lists the PowerShell cmdlets * [list-modules.ps1](Scripts/list-modules.ps1) - lists the PowerShell modules * [list-processes.ps1](Scripts/list-processes.ps1) - lists the local computer processes +* [locate-ipaddress.ps1](Scripts/locate-ipaddress.ps1) - locates the geographic position of the given IP address * [MD5.ps1](Scripts/MD5.ps1) - prints the MD5 checksum of the given file * [make-install.ps1](Scripts/make-install.ps1) - installs built executables and libs to the installation directory * [moon.ps1](Scripts/moon.ps1) - prints the current moon phase diff --git a/Scripts/locate-ipaddress.ps1 b/Scripts/locate-ipaddress.ps1 new file mode 100755 index 00000000..51255ac5 --- /dev/null +++ b/Scripts/locate-ipaddress.ps1 @@ -0,0 +1,21 @@ +#!/snap/bin/powershell + +# Syntax: ./locate-ipaddress.ps1 [] +# Description: locates the geographic position of the given IP address +# Author: Markus Fleschutz +# Source: github.com/fleschutz/PowerShell +# License: CC0 + +param([string]$IPaddr) +if ($IPaddr -eq "" ) { + $URL = read-host "Enter IP address to locate" +} + +try { + $result = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IPaddr" + write-host $result + exit 0 +} catch { + Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}