writing a Telnet client with VB. NET

Hi, I am trying to write a simple telnet client using VB.NET with Visual Studio 2005.

I am using System.Net.Sockets.

But I cant make it work yet.

What I need is:
To automate some tasks on UNIX server.
To achieve this, I need to login to unix (from within my app.) via telnet, and run some commands.
T
hats all.

Anyone can help me with this

Thanks

Fede.




Answer this question

writing a Telnet client with VB. NET

  • ManuelT

    Ok. The first thing you should do is make sure the downloaded project compiles ok. Then create a new project, I would do just a Console app for testing, add a reference to the .dll file and then do something like the following:

    Imports objActiveSolutions

    Module Module1

    Sub Main()

    Dim ip As String = "66.xx.xx.xx"

    Dim port As Integer = 23

    Dim timeout As Integer = 10

    'create the object supplying the parameters

    Dim session As New ScriptingTelnet(ip, port, timeout)

    Dim connected As Boolean = session.Connect() 'try to connect

    If connected = True Then

    'connected sucessfully

    Dim startingPrompt As Integer = session.WaitFor("Username:")

    If startingPrompt = 0 Then

    'the username prompt was found so we send the username

    'and wait to receive our password prompt

    session.SendAndWait("testuser", "Password:")

    'now send the password and wait for our next prompt

    'in this sample I expect to receive a success message

    session.SendAndWait("testpassword", "Success")

    Else

    Console.WriteLine("Username prompt was not found")

    End If

    Else

    Console.WriteLine("Unable to connect to the server")

    End If

    End Sub

    End Module

    I hope you get the feel of how to use this component to script your session.


  • AndyPham

    I found something in http://www.codeproject.com/cs/internet/terminalcontrol.asp , look at the file TerminalControl.cs (negociating sequence commands)

  • JeevesIndia

    I im trying to write a Telnet client for pocket Pc...can you help me
  • eldiener

    Hi there,
     
    I've the smae issue and I've downloaded the ScriptTelnet C# project from the URL provided above.
    Now how do I implement using that class in VB.NET
     
    I apperciate any help in advance.

  • B.Huard

    Is there a specific problem you are having with the socket communication. If you can narrow down your question we will better be able to answer it.

  • jasmine pham

    This code does not work for me either. It does not seem to be sending messages properly.


  • Clemens Vasters - MSFT

    Guys,

    I don't know what is going on here. I was in the same situation you were all in until I found that component. I gave it a shot and it just worked. I have no clue why it worked for me and not for you all. Now, there are other components out there can can script telnet sessions; but of course they are not free. Good luck you all.


  • DaveZJ

    I am having the same issue as well. I copied and pasted the prompt for "Username: " from the telnet window that I have, but it still does not work.

    Anyone have any ideas

    Thanks,

    Eric


  • Abualnassr

    TDavisjr, thans so much for the help. I've tried stepping in but I'm not seeing anything yet.
    I'll keep on working on it tho. Thanks again for putting me to the right direction.
    Wekkaw

  • selvan_06

    hey TDAVISJR thaks so much for the example above.
    I compiled and used the DLL as you suggested, but I'm getting an exception. It makes a successful connection to the server. However it waits for the "login:" prompt, and the time out occure while waiting. I tried with longer timeout values and that didn't resolve it. Do you know what may be causing that exception
    Thanks for all the help.
    Wekkaw


  • Jake.K

    yes,

    I'am Using

    System.Net.Sockets
    tcpClient

    By now i succeeded to connect to the unix server.

    I recieve this as a response: " ↑ ▼ # ' ".

    I tried to parse it with Encoding.Ascii without success. I dont get anything.

    How to negotiate the authentication process

    Thanks

    Fede



  • WinstonPennypacker

    Well, other than making sure your looking for the correct prompt because it will time out if it don't find the prompt. Also, you could try stepping into the code and see where it fails. I'm not really an expert on the inner workings of this component. I used it and it worked. I don't think there is any contact info for the author of the code so you can shoot him an email, but you can double check that. I don't know how much more I can help. Just do your best with it, if it doesn't work out then its back to the drawing board.
  • kaynos

    Hey,

    Download this sample from

    http://www.c-sharpcorner.com/UploadFile/tylerkline/TelnetScripting11282005001158AM/TelnetScripting.aspx ArticleID=a8e0e439-14df-4d82-82ee-8cb4c110f9a0

    Its just 1 source file that will compile to an assemply and you can use its public methods to script your telnet session. I had the same issue where I had to script a telnet session for a cisco interface using telnet. You may have to register to download the sample.

    If your not able to figure it out, let me know and I can post some sample code.

     


  • kawing0510

    Hello,

    This is a very good control.

    But how can I simulate "Enter" command into terminal

    Thanks



  • writing a Telnet client with VB. NET