mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-21 01:18:18 +02:00
Add check-subnet-mask.ps1
This commit is contained in:
parent
8735d0d6a5
commit
f0c3a7b25c
@ -27,6 +27,7 @@ check-ipv4-address.ps1, checks the given IPv4 address for validity
|
|||||||
check-ipv6-address.ps1, checks the given IPv6 address for validity
|
check-ipv6-address.ps1, checks the given IPv6 address for validity
|
||||||
check-mac-address.ps1, checks the given MAC address for validity
|
check-mac-address.ps1, checks the given MAC address for validity
|
||||||
check-ping.ps1, checks the ping latency to the internet
|
check-ping.ps1, checks the ping latency to the internet
|
||||||
|
check-subnet-mask.ps1, checks the given subnet mask for validity
|
||||||
check-swap-space.ps1, checks the swap space for free space left
|
check-swap-space.ps1, checks the swap space for free space left
|
||||||
check-symlinks.ps1, checks every symlink in the given directory tree
|
check-symlinks.ps1, checks every symlink in the given directory tree
|
||||||
check-weather.ps1, checks the current weather for critical values
|
check-weather.ps1, checks the current weather for critical values
|
||||||
|
|
@ -205,6 +205,7 @@ Mega Collection of PowerShell Scripts
|
|||||||
* [check-ipv4-address.ps1](Scripts/check-ipv4-address.ps1) - checks the given IPv4 address for validity
|
* [check-ipv4-address.ps1](Scripts/check-ipv4-address.ps1) - checks the given IPv4 address for validity
|
||||||
* [check-ipv6-address.ps1](Scripts/check-ipv6-address.ps1) - checks the given IPv6 address for validity
|
* [check-ipv6-address.ps1](Scripts/check-ipv6-address.ps1) - checks the given IPv6 address for validity
|
||||||
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
|
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
|
||||||
|
* [check-subnet-mask.ps1](Scripts/check-subnet-mask.ps1) - checks the given subnet mask for validity
|
||||||
* [check-weather.ps1](Scripts/check-weather.ps1) - checks the current weather for critical values
|
* [check-weather.ps1](Scripts/check-weather.ps1) - checks the current weather for critical values
|
||||||
* [convert-csv2txt.ps1](Scripts/convert-csv2txt.ps1) - converts the given CSV file to a text list
|
* [convert-csv2txt.ps1](Scripts/convert-csv2txt.ps1) - converts the given CSV file to a text list
|
||||||
* [convert-mysql2csv.ps1](Scripts/convert-mysql2csv.ps1) - converts the MySQL database table to a CSV file
|
* [convert-mysql2csv.ps1](Scripts/convert-mysql2csv.ps1) - converts the MySQL database table to a CSV file
|
||||||
|
39
Scripts/check-subnet-mask.ps1
Executable file
39
Scripts/check-subnet-mask.ps1
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
check-subnet-mask.ps1 [<address>]
|
||||||
|
.DESCRIPTION
|
||||||
|
Checks the given subnet mask for validity
|
||||||
|
.EXAMPLE
|
||||||
|
PS> .\check-subnet-mask.ps1 255.255.255.0
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz
|
||||||
|
License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
param([string]$address = "")
|
||||||
|
|
||||||
|
function IsSubNetMaskValid { param([string]$IP)
|
||||||
|
$RegEx = "^(254|252|248|240|224|192|128).0.0.0$|^255.(254|252|248|240|224|192|128|0).0.0$|^255.255.(254|252|248|240|224|192|128|0).0$|^255.255.255.(255|254|252|248|240|224|192|128|0)$"
|
||||||
|
if ($IP -match $RegEx) {
|
||||||
|
return $true
|
||||||
|
} else {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($address -eq "" ) { $address = read-host "Enter subnet mask to validate" }
|
||||||
|
|
||||||
|
if (IsSubNetMaskValid $address) {
|
||||||
|
"✔️ subnet mask $Address is valid"
|
||||||
|
exit 0
|
||||||
|
} else {
|
||||||
|
write-warning "Invalid subnet mask: $address"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user