Skip to content

Fix telnet server failing to connect on Windows#3170

Open
Moriarteh wants to merge 2 commits intoKSP-KOS:developfrom
Moriarteh:fix/telnet-npcap-loopback
Open

Fix telnet server failing to connect on Windows#3170
Moriarteh wants to merge 2 commits intoKSP-KOS:developfrom
Moriarteh:fix/telnet-npcap-loopback

Conversation

@Moriarteh
Copy link

@Moriarteh Moriarteh commented Mar 22, 2026

Fixes #3171

The Problem

On some Windows systems, the kOS telnet server listens successfully but clients can never connect — the connection hangs at "Trying 127.0.0.1..." indefinitely. No error, no rejection, just silence.

The root cause: when TcpListener binds specifically to IPAddress.Loopback (127.0.0.1), certain software that hooks the Windows loopback network interface can intercept the traffic before it reaches the application. The most common culprit is Npcap (bundled with Wireshark and Nmap), which installs its own "Npcap Loopback Adapter" — but firewalls and other network drivers can cause the same issue.

This has likely been the cause behind reports like #2937, where users saw the server listening but could never connect.

The Fix

Two changes to TelnetMainServer.cs:

  1. Bind to IPAddress.Any instead of IPAddress.Loopback when the user has configured loopback mode. This routes connections through the general network stack instead of the dedicated loopback interface, bypassing whatever is intercepting it.

  2. Reject non-loopback connections when in loopback mode. Since binding to 0.0.0.0 also listens on LAN interfaces, we explicitly check the remote address and reject anything that isn't loopback. This preserves the user's security intent.

The fix is transparent on unaffected systems — IPAddress.Any accepts loopback connections identically to IPAddress.Loopback.

Testing

  • Tested on Windows 11 with Npcap installed (via Wireshark)
  • Confirmed telnet fails with the old code, works with the fix
  • Confirmed non-loopback connections are rejected in loopback mode
  • Confirmed no change in behavior for non-loopback configurations

Checklist

Turns out, binding to 127.0.0.1 specifically can fail on Windows
if anything decides to get between you and your own computer.
Npcap (hello Wireshark users) is a known offender, but firewalls
and other network drivers can pull the same trick.

The fix: bind to 0.0.0.0 instead, which sidesteps whatever is
lurking on the loopback interface. But since we don't actually
want the whole neighbourhood connecting to our kOS terminal,
non-loopback connections are rejected when the user configured
loopback mode.

Works with or without Npcap. Works on systems that were never
broken. Mostly just works, which is a nice change for networking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telnet server fails to accept connections on Windows with loopback network interception

1 participant