473,231 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Asp.net web telnet client problems

1
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 3820

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

Similar topics

4
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
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
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
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
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
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
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
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
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
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.