Created
April 3, 2025 06:23
-
-
Save takumaw/be16357784dc39bcb1498f3930039ed6 to your computer and use it in GitHub Desktop.
WSL2 to PanGP
This file contains hidden or 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
# define function | |
function Get-NetworkAddress { | |
param([Parameter(Mandatory, ValueFromPipelineByPropertyName)][string]$IPAddress, [Parameter(Mandatory, ValueFromPipelineByPropertyName)][int]$PrefixLength); | |
process { | |
$bitNwAddr = [ipaddress]::Parse($IPAddress).Address -band [uint64][BitConverter]::ToUInt32([System.Linq.Enumerable]::Reverse([BitConverter]::GetBytes([uint32](0xFFFFFFFFL -shl (32 - $PrefixLength) -band 0xFFFFFFFFL))), 0); | |
[pscustomobject]@{ | |
Addr = $IPAddress; | |
Prfx = $PrefixLength; | |
NwAddr = [ipaddress]::new($bitNwAddr).IPAddressToString + '/' + $PrefixLength; | |
}; | |
} | |
} | |
# shorten vm metric | |
$hvIfs = Get-NetAdapter -IncludeHidden | Where-Object InterfaceDescription -Match 'Hyper-V Virtual Ethernet Adapter'; | |
$hvAddresses = $hvIfs | Get-NetIPAddress -AddressFamily IPv4 | Get-NetworkAddress; | |
$hvIfs | Set-NetIPInterface -InterfaceMetric 1; | |
$hvIfs | Get-NetRoute -AddressFamily IPv4 | Select-Object -PipelineVariable rt | Where-Object { $hvAddresses | Where-Object { $_.NwAddr -eq (Get-NetworkAddress $rt.DestinationPrefix.Split('/')[0] $_.Prfx).NwAddr } } | Set-NetRoute -RouteMetric 0 -PassThru; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment