PDA

Click to See Complete Forum and Search --> : Telnet Question


Rucypher
Jan 18th, 2010, 12:46 AM
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!

cicatrix
Jan 18th, 2010, 04:30 AM
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.


Dim host As String = "hostname"
' Creating endpoint
Dim iep As New Net.IPEndPoint(Net.IPAddress.Any, 23)

' Creating TCP client
Dim tcp As New Net.Sockets.TcpClient(iep)

' Connecting to host
tcp.Connect(host, 23)
If tcp.Connected Then
Dim str As Net.Sockets.NetworkStream = tcp.GetStream
Dim sr As New IO.StreamReader(str)
Dim sw As New IO.StreamWriter(str)

' write to the network stream with sw
'read from the network stream with sr

' do something else
' close connection
tcp.Close()
End If

Rucypher
Jan 18th, 2010, 08:51 AM
Thank you very much!

dilettante
Jan 18th, 2010, 01:36 PM
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.