Sending Control-N and <CR><LF> via telnet using C#

有些话、适合烂在心里 提交于 2019-12-13 05:35:52

问题


I am currently using minimalistic Telnet from CodeProject and am having trouble sending the correct output to my telnet device. Essentially I am trying to automate the gathering of config data from Netopia DSL modems using this process. I am able to read the welcome screen of the netopia telnet interface just fine however I can not get any further.

The process manually goes like this: 1) Telnet to device ip 2) A welcome screen is displayed. 3) While on the welcome screen, press Control-N 4) Presented with a # prompt 5) sh config would print the config file to the screen.

Any help is very much appreciated.


回答1:


These are ascii codes.

char ctrln = (char)0x0E;
char cr = '\r';
char lf = '\n';

I've not tested the ctrl+n one but the other two should work.




回答2:


var login = "Login"+Environment.NewLine; // add carriage return at the end of text
var password = "Password" +Environment.NewLine;
telnetComponent.Send(login);
telnetComponent.Send(password);


来源:https://stackoverflow.com/questions/5022005/sending-control-n-and-crlf-via-telnet-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!