tags:

views:

7644

answers:

7
+5  Q: 

C# Telnet Library

Is there a good, free telnet library available for C# (not ASP .NET)? I have found a few on google, but they all have one issue or another (don't support login/password, don't support a scripted mode).

I am assuming that MS still has not included a telnet library as part of .NET v3.5 as I couldn't find it if it was. I would loooooove to be wrong though.

+1  A: 

I doubt very much a telnet library will ever be part of the .Net BCL, although you do have almost full socket support so it wouldnt be too hard to emulate a telnet client, Telnet in its general implementation is a legacy and dying technology that where exists generally sits behind a nice new modern facade. In terms of Unix/Linux variants you'll find that out the box its SSH and enabling telnet is generally considered poor practice.

You could check out: http://granados.sourceforge.net/ - SSH Library for .Net http://www.tamirgal.com/home/dev.aspx?Item=SharpSsh

You'll still need to put in place your own wrapper to handle events for feeding in input in a scripted manner.

The issue is that I am trying to telnet into a remote device that only has telnet enabled. I am not trying to setup a machine. SSH is not an option. Telnet is the only option. I can run the command by hand or I can use a little program to do it for me. Thanks for the links.
salt.racer
+1  A: 

there are several on the CodeProject

here 'i think this is the one i use, although im not sure
Search

But you can also telnet using the Net.Sockets class too:

_socket = New Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
_socket.Connect(address, port)

Private Sub SendCommand(ByVal cmd As String)

 If Not String.IsNullOrEmpty(cmd) Then

  Dim send() As Byte = Text.Encoding.ASCII.GetBytes(cmd & vbCrLf)

  _socket.Send(send, send.Length, SocketFlags.None)

  Threading.Thread.Sleep(50) 'used as the code used for the response can fire too quickly

 End If

End Sub

EDIT: Added comments

Pondidum
I don't understand why you allocate an unused buffer and the purpose of the call to Thread.Sleep.
Tmdean
Thanks. I think that is what I am going to have to do. As it turns out the device that I am attempting to login to doesn't have a user name, but it does have a password. And no command prompt either. Crazy stupid device.
salt.racer
(so even good libraries are useless)
salt.racer
Do'h ... your code is VB. :) Thanks though.
salt.racer
cant you read VB? :p just stick semi-colons at the end and have done with it!as for the buffer, i think that was a line i forgot to remove, this is a cut down version of what i use.
Pondidum
A: 

I ended up finding MinimalistTelnet and adapted it to my uses. I ended up needing to be able to heavily modify the code due to the unique** device that I am attempting to attach to.

** Unique in this instance can be validly interpreted as brain-dead.

salt.racer
A: 

Hi,

I am currently evaluating two .NET (v2.0) C# Telnet libraries that may be of interest:

Hope this helps.

Regards, Andy.

MagicAndi
+7  A: 

Best C# Telnet Lib I've found is called Minimalistic Telnet. Very easy to understand, use and modify. It works great for the Cisco routers I need to configure.

http://www.codeproject.com/KB/IP/MinimalisticTelnet.aspx

Richard
That's exactly the one that worked for me for the very reasons you outlined. I'm glad I'm not alone in liking it. :)
salt.racer
Minimalistic telnet worked perfectly for me and our LAN team. I ended up modifying it to read commands from a text file so our LAN team could easily deploy it.
Ben McCormack
+1  A: 

Here is a telnet library and program that uses it as an example. All the source (including the library source) is at the bottom of the article.

The example performs a login to a Cisco router and downloads the configuration

http://www.xpresslearn.com/networking/code/csharp-telnet-client

Scott
A: 

Another one with a different concept: http://www.klausbasan.de/misc/telnet/index.html

HOWA