Created
January 24, 2023 20:13
-
-
Save quonic/4c86ad44fe26c25b3cf0931d6cbfd1d5 to your computer and use it in GitHub Desktop.
A simple class for defining an IPv4 address, accessing or changing any octet. Uses the Version object as the base object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IP { | |
IP([string]$Address) { | |
$this._IPAddress = $Address | |
} | |
hidden [Version] $_IPAddress = $($this | Add-Member ScriptProperty 'Address' { | |
# get | |
[PSCustomObject]@{ | |
First = $this._IPAddress.Major | |
Second = $this._IPAddress.Minor | |
Third = $this._IPAddress.Build | |
Forth = $this._IPAddress.Revision | |
} | |
} { | |
# set | |
param ( $arg ) | |
$this._IPAddress = $arg | |
} | |
) | |
[string] ToString() { | |
return $this._IPAddress.ToString() | |
} | |
[IPAddress] ToIPAddress() { | |
return [IPAddress]::Parse($this._IPAddress.ToString()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment