mirror of
https://github.com/Andre-Bzk/tunnler.git
synced 2026-11-15 12:33:03 +01:00
fix: make tunnel start despite unreadable DNS answers
wstunnel's built-in DNS resolver fails on some DNS servers because it cannot read their EDNS answers. With a connection pool the client then never opened the local port. Use the Windows resolver instead. The port check also took ~2 s per attempt, so the start script showed an empty window for a long time before the error appeared.
This commit is contained in:
@@ -14,7 +14,11 @@ $LogDir = Join-Path $ClientDir 'logs'
|
|||||||
$ProxyUrl = "http://$LocalProxy"
|
$ProxyUrl = "http://$LocalProxy"
|
||||||
|
|
||||||
function Get-TunnelArgs([string]$LogLevel) {
|
function Get-TunnelArgs([string]$LogLevel) {
|
||||||
$tunnelArgs = @('client', '-L', "http://$LocalProxy", '-c', '2', '--log-lvl', $LogLevel)
|
# Windows-Resolver statt des eingebauten: Manche DNS-Server liefern EDNS-Antworten,
|
||||||
|
# die wstunnel nicht lesen kann. Dann scheitert jede Verbindung, und mit -c wartet
|
||||||
|
# der Client endlos auf den Pool, bevor er den lokalen Port oeffnet.
|
||||||
|
$tunnelArgs = @('client', '-L', "http://$LocalProxy", '-c', '2', '--log-lvl', $LogLevel,
|
||||||
|
'--dns-resolver', 'system://0.0.0.0')
|
||||||
if (-not $SkipTlsVerify) { $tunnelArgs += '--tls-verify-certificate' }
|
if (-not $SkipTlsVerify) { $tunnelArgs += '--tls-verify-certificate' }
|
||||||
if ($UpstreamProxy) { $tunnelArgs += @('--http-proxy', $UpstreamProxy) }
|
if ($UpstreamProxy) { $tunnelArgs += @('--http-proxy', $UpstreamProxy) }
|
||||||
if ($UpstreamProxyUser) { $tunnelArgs += @('--http-proxy-login', $UpstreamProxyUser) }
|
if ($UpstreamProxyUser) { $tunnelArgs += @('--http-proxy-login', $UpstreamProxyUser) }
|
||||||
@@ -44,7 +48,8 @@ function Invoke-WithTunnelEnv([scriptblock]$Action) {
|
|||||||
function Test-TunnelListening {
|
function Test-TunnelListening {
|
||||||
$parts = $LocalProxy.Split(':')
|
$parts = $LocalProxy.Split(':')
|
||||||
$client = New-Object System.Net.Sockets.TcpClient
|
$client = New-Object System.Net.Sockets.TcpClient
|
||||||
try { $client.Connect($parts[0], [int]$parts[1]); return $true }
|
# Connect() auf einen geschlossenen Port dauert unter Windows ~2 s (SYN-Wiederholungen)
|
||||||
|
try { return $client.ConnectAsync($parts[0], [int]$parts[1]).Wait(500) -and $client.Connected }
|
||||||
catch { return $false }
|
catch { return $false }
|
||||||
finally { $client.Close() }
|
finally { $client.Close() }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user