9swampy / Telnet

Published on Nuget at https://www.nuget.org/packages/Telnet
http://www.nugetmusthaves.com/Package/Telnet
MIT License
126 stars 50 forks source link

Telnet to H3C switch #45

Closed yf2468 closed 4 years ago

yf2468 commented 5 years ago

It can't read ":",may be include enter. Thank you.

public async Task ReadmeExample() { using (TelnetServer server = new TelnetServer()) { //using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) using (Client client = new Client("193.125.2.100", 23, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (await client.TryLoginAsync("username", "password", timeoutMs)).Should().Be(true); await client.WriteLine("show statistic wan2"); string s = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(timeoutMs)); s.Should().Contain(">"); s.Should().Contain("WAN2"); System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex("(?!WAN2 total TX: )([0-9.])(?! GB ,RX: )([0-9.])(?= GB)"); regEx.IsMatch(s).Should().Be(true); MatchCollection matches = regEx.Matches(s); decimal tx = decimal.Parse(matches[0].Value); decimal rx = decimal.Parse(matches[1].Value); (tx + rx).Should().BeLessThan(50); } } }

Debug Trace: SENT: ÿ SENT: þ SENT:  SENT: ÿ SENT: þ SENT:  SENT: ÿ SENT: þ SENT:  SENT: ÿ SENT: ý SENT:  SENT: ÿ SENT: ü SENT:  SENT: ÿ SENT: ü SENT:  23:796: RollingTimeout exceeded {0} 23:812: RollingTimeout exceeded {0} SENT: ÿ SENT: þ SENT:  SENT: ÿ SENT: þ SENT:  SENT: ÿ SENT: þ SENT:  23:827: RollingTimeout exceeded {0} 23:842: RollingTimeout exceeded {0} 23:858: RollingTimeout exceeded {0} 23:874: RollingTimeout exceeded {0} Failed to terminate '


A9G-Data-Droid commented 4 years ago

It's looking for the : after the main login. Looks like it gives up before the login prompt ever appears. Looking at that switch it has a wait that looks like this:

Press ENTER to get started.

You need to send a newline before you TryLoginAsync.

Like this:

client.IsConnected.Should().Be(true);
client.WriteLine("");
(await client.TryLoginAsync("username", "password", timeoutMs)).Should().Be(true);
9swampy commented 4 years ago

Thx @A9G-Data-Droid