Skip to content

Commit

Permalink
fix(ps): wsl_network_fix
Browse files Browse the repository at this point in the history
Network adapter choice menu.
  • Loading branch information
szymonos committed Oct 13, 2023
1 parent 20cf1ff commit 8b836c2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions wsl/wsl_network_fix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ begin {
}

# instantiate string builder
$builder = [System.Text.StringBuilder]::new("# Generated by wsl_network_fix.ps1 on $((Get-Date).ToString('s'))")
$builder = [System.Text.StringBuilder]::new("# Generated by wsl_network_fix.ps1 on $((Get-Date).ToString('s'))`n")
}

process {
Expand Down Expand Up @@ -113,20 +113,20 @@ process {
$idx = -1
$selection = Read-Host -Prompt "Please select the interface for propagating DNS Servers:`n$($list | Format-Table | Out-String)"
[bool]$returnedInt = [int]::TryParse($selection, [ref]$idx)
} until ($returnedInt -and $idx -ge 0 -and $idx -lt $netAdapters.Count)
} until ($returnedInt -and $idx -ge 0 -and $idx -lt $ipConfig.Count)
$dnsServers = $ipConfig[$idx].DNSServer
$dnsServers.ForEach({ $builder.AppendLine("nameserver $_") | Out-Null })
}
# get DNS suffix search list
$searchSuffix = (Get-DnsClientGlobalSetting).SuffixSearchList -join ','
if ($searchSuffix) {
$builder.AppendLine("search $searchSuffix") | Out-Null
}
# get distro default gateway
$def_gtw = (wsl.exe -d $Distro -u root --exec sh -c 'ip route show default' | Select-String '(?<=via )[\d\.]+(?= dev)').Matches.Value
if ($def_gtw) {
$builder.AppendLine("nameserver $def_gtw") | Out-Null
}
# get DNS suffix search list
$searchSuffix = (Get-DnsClientGlobalSetting).SuffixSearchList -join ','
if ($searchSuffix) {
$builder.AppendLine("search $searchSuffix") | Out-Null
}
$builder.AppendLine('options timeout:1 retries:1') | Out-Null
$resolvConf = $builder.ToString().Replace("`r`n", "`n")
# save resolv.conf file
Expand Down

0 comments on commit 8b836c2

Please sign in to comment.