mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-06 16:44:58 +02:00
Renamed to list-public-ip.ps1
This commit is contained in:
parent
c227fd586b
commit
100b298870
@ -1,30 +0,0 @@
|
|||||||
<#
|
|
||||||
.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.77.209.161, IPv6 2003:f2:6128:fc01:e503:601:30c2:a028 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
|
|
||||||
}
|
|
@ -21,5 +21,5 @@
|
|||||||
& "$PSScriptRoot/check-ping.ps1"
|
& "$PSScriptRoot/check-ping.ps1"
|
||||||
& "$PSScriptRoot/check-dns.ps1"
|
& "$PSScriptRoot/check-dns.ps1"
|
||||||
& "$PSScriptRoot/check-vpn.ps1"
|
& "$PSScriptRoot/check-vpn.ps1"
|
||||||
& "$PSScriptRoot/check-ip.ps1"
|
& "$PSScriptRoot/list-public-ip.ps1"
|
||||||
exit 0 # success
|
exit 0 # success
|
33
Scripts/list-public-ip.ps1
Normal file
33
Scripts/list-public-ip.ps1
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Lists the public IP address(es)
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script queries the public IP address(es) and prints it.
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./list-public-ip.ps1
|
||||||
|
✅ Public IPv4 185.72.209.161, IPv6 2003:f2:6128:fc01:e503:601:30c2:a028 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)
|
||||||
|
}
|
||||||
|
if ("$publicIPv4" -eq "") { $publicIPv4 = "N/A" }
|
||||||
|
if ("$publicIPv6" -eq "") { $publicIPv6 = "N/A" }
|
||||||
|
if ("$city" -eq "") { $city = "unknown" }
|
||||||
|
Write-Output "✅ Public IPv4 $publicIPv4, IPv6 $publicIPv6 near $City"
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user