Results 1 to 4 of 4

Thread: Telnet Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    2

    Telnet Question

    Hi,

    I'm very new to VB programming. I've been tasked with building a program that will telnet into a network appliance, execute commands, and then retrieve the data in a report format. I'm needing to know if this is possible using VB, and also if there are any guides or examples out there to follow?

    Thanks!

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Telnet Question

    Generally:
    1. Create IPEndPoint (your IP address, port =23) ' or custom port used by the appliance.
    2. Use TCPClient object
    3. Connect to your appliance via port 23
    4. Open network stream for communication
    5. Write commands to your stream and read your stream for a response.

    I didn't test this code, but it should work

    For serious task you may want to use asyncronous communication with the host.

    vb.net Code:
    1. Dim host As String = "hostname"
    2. ' Creating endpoint
    3. Dim iep As New Net.IPEndPoint(Net.IPAddress.Any, 23)
    4.  
    5. ' Creating TCP client
    6. Dim tcp As New Net.Sockets.TcpClient(iep)
    7.  
    8. ' Connecting to host
    9. tcp.Connect(host, 23)
    10. If tcp.Connected Then
    11.     Dim str As Net.Sockets.NetworkStream = tcp.GetStream
    12.     Dim sr As New IO.StreamReader(str)
    13.     Dim sw As New IO.StreamWriter(str)
    14.  
    15.     ' write to the network stream with sw
    16.     'read from the network stream with sr
    17.  
    18.     ' do something else
    19.     ' close connection
    20.     tcp.Close()
    21. End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    2

    Re: Telnet Question

    Thank you very much!

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Telnet Question

    Be careful, Telnet is not a dumb TCP connection.

    Many *nix-based appliances don't really do Telnet though so you might be safe. Anything smarter is likely to initiate option negotiation which can hang you up using a simple TCP connection though. Then there is always the issue of terminal types, emulation, and the resulting escape sequences and such in the data stream.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width