mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-18 00:20:09 +02:00
Added check-ipv4-address.ps1 and check-mac-address.ps1
This commit is contained in:
28
Scripts/check-ipv4-address.ps1
Executable file
28
Scripts/check-ipv4-address.ps1
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./check-ipv4-address.ps1 [<address>]
|
||||
# Description: checks the given IPv4 address for validity
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
param([string]$Addr)
|
||||
|
||||
# IPv4-Address like 192.168.178.1
|
||||
$RegEx = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||
|
||||
try {
|
||||
if ($Addr -eq "" ) {
|
||||
$Addr = read-host "Enter IPv4 address to validate"
|
||||
}
|
||||
if ($Addr -match $RegEx) {
|
||||
write-output "IPv4 address $Addr is valid"
|
||||
exit 0
|
||||
} else {
|
||||
write-output "IPv4 address $Addr is NOT valid"
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Reference in New Issue
Block a user