473,513 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asp.net web telnet client problems

1 New Member
I am trying to create a telnet client that will connect to several of my network devices on campus and change settings on the devices. So far I can connect with the code below, but I can't seem to get the correct return data from the device. Sometimes I get about 100 bytes and other times I get 3000 bytes. I even put a thread sleep but that still give me different return data from different devices. I know I am going to have to use an asynccallback but I just don't know how to do that. Any help would be great. I have also tried to use networkstream.dataavailable but this still is sporatic data.

<%@ Page Language="VB" debug="true"%>
<%@ Import Namespace = "System.Web" %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.Net.Sockets" %>
<%@ Import NameSpace="System.Threading" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Dim tcpClient As New System.Net.Sockets.TcpClient
Dim networkStream As NetworkStream
Dim numBytesRead As Integer
Dim returndata As String
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
Dim sendBytes As [Byte]()

Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

tcpClient.Connect("10.6.8.0", 23)
networkStream = tcpClient.GetStream()
numBytesRead = networkStream.Read(bytes, 0, tcpClient.ReceiveBufferSize)

Send_Receive(vbCr, "Ctrl-Y", 0)
Send_Receive(ControlKeyPressed("Y"), "Enter Password:", 0)
Send_Receive("mypasswordis123" & vbCr, "Setup", 0)
Send_Receive("c", "#", 0)

Response.Write("<BR><BR>" & returndata)
Send_Receive("show mac-address-table vid 20 address 000b.db6e.8208" & vbCr, "#", 1000)
Response.Write("<BR><BR>" & returndata)

Send_Receive("logout" & vbCr, "Setup", 0)
sendBytes = Encoding.ASCII.GetBytes("l")
networkStream.Write(sendBytes, 0, sendBytes.Length)


'If networkStream.CanRead Then
' Response.Write("loop 1")
' Dim myReadBuffer(5000) As Byte
' Dim myCompleteMessage As StringBuilder = New StringBuilder()
' Dim numberOfBytesRead As Integer = 0

' ' Incoming message may be larger than the buffer size.
' Do
' numberOfBytesRead = networkStream.Read(bytes, 0, 1)
' myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(bytes, 0, 5000))

' Loop While networkStream.DataAvailable
' Thread.Sleep(100)
' ' Print out the received message to the console.
' Response.Write(("You received the following message : " + myCompleteMessage.ToString()))
'Else
' Response.Write("Sorry. You cannot read from this NetworkStream.")
'End If

tcpClient.Close()
networkStream.Close()

End Sub

' This function sends the Ctrl key to the telnet server
Function ControlKeyPressed(ByVal character)
ControlKeyPressed = Chr(Asc(character) - 64)
End Function

' This function sends data to the telnet server and waits for data to be returned from the telnet server.
Function Send_Receive(ByVal Sending As String, ByVal Finding As String, ByVal Pause As Integer)
sendBytes = Encoding.ASCII.GetBytes(Sending)
networkStream.Write(sendBytes, 0, sendBytes.Length)

' Pause let the returned data buffer complete.
Thread.Sleep(Pause)
Do
numBytesRead = networkStream.Read(bytes, 0, tcpClient.ReceiveBufferSize)
returndata = Encoding.ASCII.GetString(bytes, 0, numBytesRead)
bytes.Clear(bytes, 0, bytes.Length)
Loop While InStr(returndata, Finding) = 0
Return returndata
End Function

</script>
Aug 26 '06 #1
0 3834

Sign in to post your reply or Sign up for a free account.

Similar topics

4
13453
by: Tom Lynn | last post by:
I'm considering using a PHP command line script to retrieve reports from a Linux system. My only source for the report is via telnet. Has anybody here used fsockopen() to interactively script a...
2
50243
by: Dan | last post by:
I'm writing a simplistic telnet client in VB6 and I've run into a small snag. The program has a textbox to write in the string to be sent using ..SendData and has another textbox that displays...
3
8644
by: Yannick Turgeon | last post by:
Hello all, I'm currently trying to pass commands to a telnet session and get the texte generated (stdin + stdout) by the session. The problem I get is that the Telnet.read_until() function...
6
5213
by: Donnal Walter | last post by:
Several months ago I tried using the telnet module (on Windows XP) to communicate with a proprietary host on our network. This was unsuccessful due to problems with "option negotiation", and I gave...
2
4888
by: Bruce W...1 | last post by:
I've got MySQL running as a service on my Windows 2000 box. And I can work with it using a command window (DOS box). I used the default install of MySQL and here's what status says: mysql>...
7
14074
by: Rex Winn | last post by:
I've Googled until my eyes hurt looking for a way to issue Telnet commands from C# and cannot find anything but $300 libraries that encapsulate it for you. I don't want to be able to create a...
2
5164
by: thilandeneth | last post by:
i need to do telnet via a web server please give me a idia to initiate the project following requirements are needed 1 Create web based custom telnet client to communicate with remote...
13
3131
by: Godzilla | last post by:
Hello, How do you create/spawn new processes in XP over telnet using python? I.e. I would like to create a new process and have it running in the background... when I terminate the telnet...
5
8741
by: pbd22 | last post by:
Hi. Anybody know of any good code examples out there on how to take a telnet command and parse it? Thanks!
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.