Skip to content

Commit 54c9a35

Browse files
committed
[PE Helper/PXE Helpers] Add IPv6 support
1 parent f9da99b commit 54c9a35

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

Helpers/extps1/PE_Helper/pxehelpers/common/PXEHelpers.Common.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ using namespace System.Collections.Generic
33
$global:product = ""
44
$global:description = ""
55

6+
enum IPAddress {
7+
IPv4 = 0
8+
IPv6 = 1
9+
Unknown = 2
10+
}
11+
612
function Show-CenteredTextBox {
713
param (
814
[string]$Text,
@@ -115,3 +121,25 @@ function Disable-Networking {
115121
Remove-Item -Path "$env:SYSTEMDRIVE\net_initiated" -Force
116122
}
117123
}
124+
125+
function Test-IPAddressSyntax {
126+
param (
127+
[Parameter(Mandatory, Position = 0)] [string]$ipAddr
128+
)
129+
130+
# For some stupid reason, the regex method that works in both a non-WinPE PWSH session and in a .NET application does
131+
# NOT work on WinPE. GPT suggested using the IPAddress.AddressFamily property, and it produces viable results under a debugger environment. So
132+
# we'll use these here.
133+
134+
# We'll first check IPv4, then IPv6
135+
$parsed = $null
136+
if ([System.Net.IPAddress]::TryParse($ipAddr.Trim(), [ref]$parsed)) {
137+
if ($parsed.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork) {
138+
return [IPAddress]::IPv4
139+
} elseif ($parsed.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6) {
140+
return [IPAddress]::IPv6
141+
}
142+
}
143+
144+
return [IPAddress]::Unknown
145+
}

Helpers/extps1/PE_Helper/pxehelpers/fog/foghelper.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class ServerAuthentication {
1414
$this.serverIP = $ip
1515
$this.serverPort = $port
1616
$this.serverUnderlyingFogServerIP = $underlyingIp
17+
18+
if ((Test-IPAddressSyntax -ipAddr $this.serverIP) -eq [IPAddress]::IPv6) {
19+
$this.serverIP = "[$($this.serverIP)]"
20+
}
1721
}
1822
}
1923

Helpers/extps1/PE_Helper/pxehelpers/wds/wdshelper.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class ServerAuthentication {
1616
$this.serverPort = $port
1717
$this.serverUser = $user
1818
$this.serverPassword = $password
19+
20+
if ((Test-IPAddressSyntax -ipAddr $this.serverIP) -eq [IPAddress]::IPv6) {
21+
$this.serverIP = "[$($this.serverIP)]"
22+
}
1923
}
2024
}
2125

0 commit comments

Comments
 (0)