2009-06-27 4 views
12

これは簡単ですか?いずれかの良い例がありますか?私のすべてのGoogle検索では、ドットネットのtelnetクライアントを作成する方法についての項目が返されますが、この過剰なものは私のためにあります。私はC#でこれをやろうとしています。C#でtelnet接続を開き、いくつかのコマンドを実行する方法

ありがとうございます!

答えて

4

を音としてテキストコマンドで十分でしょう。

実際のTelnetサーバに接続する場合は、telnetエスケープシーケンス、端末エミュレーション、対話型コマンドなどを処理する必要があるかもしれません。Minimalistic Telnet library from CodeProject(無料)や市販のTelnet/Terminal Emulatorライブラリ(Rebex Telnetなど)を使用すると、時間を節約できます。 (this urlから取られた)次のコード

はそれを使用する方法を示しています。

// create the client 
Telnet client = new Telnet("servername"); 

// start the Shell to send commands and read responses 
Shell shell = client.StartShell(); 

// set the prompt of the remote server's shell first 
shell.Prompt = "servername# "; 

// read a welcome message 
string welcome = shell.ReadAll(); 

// display welcome message 
Console.WriteLine(welcome); 

// send the 'df' command 
shell.SendCommand("df"); 

// read all response, effectively waiting for the command to end 
string response = shell.ReadAll(); 

// display the output 
Console.WriteLine("Disk usage info:"); 
Console.WriteLine(response); 

// close the shell 
shell.Close(); 
関連する問題