Add check-subnet-mask.ps1

This commit is contained in:
Markus Fleschutz 2021-08-27 15:35:34 +02:00
parent 8735d0d6a5
commit f0c3a7b25c
3 changed files with 41 additions and 0 deletions

View File

@ -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-mac-address.ps1, checks the given MAC address for validity
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-symlinks.ps1, checks every symlink in the given directory tree
check-weather.ps1, checks the current weather for critical values

1 Script Description
27 check-ipv6-address.ps1 checks the given IPv6 address for validity
28 check-mac-address.ps1 checks the given MAC address for validity
29 check-ping.ps1 checks the ping latency to the internet
30 check-subnet-mask.ps1 checks the given subnet mask for validity
31 check-swap-space.ps1 checks the swap space for free space left
32 check-symlinks.ps1 checks every symlink in the given directory tree
33 check-weather.ps1 checks the current weather for critical values

View File

@ -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-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-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
* [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

39
Scripts/check-subnet-mask.ps1 Executable file
View 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
}