|
-
Jan 18th, 2010, 01:46 AM
#1
Thread Starter
New Member
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!
-
Jan 18th, 2010, 05:30 AM
#2
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:
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
Last edited by cicatrix; Jan 18th, 2010 at 05:39 AM.
-
Jan 18th, 2010, 09:51 AM
#3
Thread Starter
New Member
-
Jan 18th, 2010, 02:36 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|