473,666 Members | 2,048 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.d ataavailable but this still is sporatic data.

<%@ Page Language="VB" debug="true"%>
<%@ Import Namespace = "System.Web " %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.Net.Soc kets" %>
<%@ Import NameSpace="Syst em.Threading" %>
<%@ import Namespace="Syst em.Data" %>
<%@ import Namespace="Syst em.Data.SqlClie nt" %>


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

<script runat="server">

Dim tcpClient As New System.Net.Sock ets.TcpClient
Dim networkStream As NetworkStream
Dim numBytesRead As Integer
Dim returndata As String
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
Dim sendBytes As [Byte]()

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

tcpClient.Conne ct("10.6.8.0", 23)
networkStream = tcpClient.GetSt ream()
numBytesRead = networkStream.R ead(bytes, 0, tcpClient.Recei veBufferSize)

Send_Receive(vb Cr, "Ctrl-Y", 0)
Send_Receive(Co ntrolKeyPressed ("Y"), "Enter Password:", 0)
Send_Receive("m ypasswordis123" & vbCr, "Setup", 0)
Send_Receive("c ", "#", 0)

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

Send_Receive("l ogout" & vbCr, "Setup", 0)
sendBytes = Encoding.ASCII. GetBytes("l")
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)


'If networkStream.C anRead Then
' Response.Write( "loop 1")
' Dim myReadBuffer(50 00) As Byte
' Dim myCompleteMessa ge As StringBuilder = New StringBuilder()
' Dim numberOfBytesRe ad As Integer = 0

' ' Incoming message may be larger than the buffer size.
' Do
' numberOfBytesRe ad = networkStream.R ead(bytes, 0, 1)
' myCompleteMessa ge.AppendFormat ("{0}", Encoding.ASCII. GetString(bytes , 0, 5000))

' Loop While networkStream.D ataAvailable
' Thread.Sleep(10 0)
' ' Print out the received message to the console.
' Response.Write( ("You received the following message : " + myCompleteMessa ge.ToString()))
'Else
' Response.Write( "Sorry. You cannot read from this NetworkStream." )
'End If

tcpClient.Close ()
networkStream.C lose()

End Sub

' This function sends the Ctrl key to the telnet server
Function ControlKeyPress ed(ByVal character)
ControlKeyPress ed = Chr(Asc(charact er) - 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(By Val Sending As String, ByVal Finding As String, ByVal Pause As Integer)
sendBytes = Encoding.ASCII. GetBytes(Sendin g)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)

' Pause let the returned data buffer complete.
Thread.Sleep(Pa use)
Do
numBytesRead = networkStream.R ead(bytes, 0, tcpClient.Recei veBufferSize)
returndata = Encoding.ASCII. GetString(bytes , 0, numBytesRead)
bytes.Clear(byt es, 0, bytes.Length)
Loop While InStr(returndat a, Finding) = 0
Return returndata
End Function

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

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

Similar topics

4
13465
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 telnet session in PHP? If so, what problems did you have to overcome. If not, does this sound do-able?
2
50297
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 what that server sends. When I first connect to the server (in this case, my university's smtp server), I get a response that the server acknowledges my connection. When I type something into the textbox and send it, however, I get no response...
3
8658
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 seems to freeze after a couple of command. I did a simplify script that reproduce the problem each time (I'm using 2.3.4 on W2K):
6
5220
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 up on the project for a while. I still have need for this, however, so I recently started thinking about alternatives. I suppose I could dig deep enough into option negotiation to use the socket module (with telnet as a guide), but I am hoping...
2
4892
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> status -------------- mysql Ver 12.21 Distrib 4.0.15, for Win95/Win98 Connection id: 5 Current database:
7
14089
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 Telnet client. I just need to send a telnet request to a local IP address on a LAN issue a "c" then a "b" and stream back the text for internal use. The "c" changes sub-menus and the "b" is a switch to dump the status of a firewall. I need to issue...
2
5178
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 destinations. must provide login security before make communication 2 telnet communication should not be a direct 1 to 1 communication and that must be as follows Web telnet client -à Web server (telnet client) -à destination (see figure 01)
13
3147
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 connection, I would what the spawned processes to keep running until I shut it off... I got the os.popen method to spawn a new process running in the backgroun, but not over telnet... tried os.popen and also subprocesses.popen without any luck...
5
8772
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
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.