Add check-ip.ps1

This commit is contained in:
Markus Fleschutz 2023-08-04 11:02:26 +02:00
parent 882d0d4e7a
commit 2545d4f8db
2 changed files with 31 additions and 0 deletions

30
Scripts/check-ip.ps1 Normal file
View File

@ -0,0 +1,30 @@
<#
.SYNOPSIS
Checks the IP address
.DESCRIPTION
This PowerShell script queries the public IP address and prints it.
.EXAMPLE
PS> ./check-ip.ps1
Public IPv4 185.74.219.161, IPv6 2003:f2:6729:fc00:e563:641:3dc2:a628, near Munich
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
if ($IsLinux) {
$PublicIPv4 = (curl -4 --silent ifconfig.co)
$PublicIPv6 = (curl -6 --silent ifconfig.co)
$City = (curl --silent ifconfig.co/city)
} else {
$PublicIPv4 = (curl.exe -4 --silent ifconfig.co)
$PublicIPv6 = (curl.exe -6 --silent ifconfig.co)
$City = (curl.exe --silent ifconfig.co/city)
}
Write-Output "✅ Public IPv4 $PublicIPv4, IPv6 $PublicIPv6, near $City"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -21,4 +21,5 @@
& "$PSScriptRoot/check-ping.ps1"
& "$PSScriptRoot/check-dns.ps1"
& "$PSScriptRoot/check-vpn.ps1"
& "$PSScriptRoot/check-ip.ps1"
exit 0 # success