Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

VB2005 : Send input to a TELNET process - IP/User/Password/Sign-on

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Screaming Eagles 101 - 15 Oct 2007 10:11 GMT
Hi,

I looked and found a lot of different code regarding send/receiving
input/output to a command window, but none helped me so far.

I would like to start a process with telnet a bit like this
myProcess.StartInfo.FileName = "telnet.exe"
myProcess.StartInfo.Arguments = " -a 199.99.99.99 299" ' (IP and port) =
this works....

then wait for the process to be ready

to send the user + wait

to send the password + wait

to send the sign-on option and quit the process

I didn't find anything that was useful to help me.

I found code with streamreaders and streamwriters and redirecting input and
output,

problem is I don't have a cmd window anymore and I don't see anything
happening, also it's not working because the connection fails...

Signature

Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------

Dick Grier - 15 Oct 2007 19:50 GMT
Hi,

System.Net.Sockets.TcpClient is the class name.

You would open a TCP/IP socket (the TcpClient) using the telnet server
Address and Port(typically, port 23, but some servers may use another port
number) as a stream

You then set a TextWriter to use the stream just opened and write your
output using the TextWriter Write method.  You can use Thread.Sleep to add a
delay after the Write.

Dick

Signature

Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.

Screaming Eagles 101 - 16 Oct 2007 08:56 GMT
Signature

Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------

> Hi,
>
[quoted text clipped - 9 lines]
>
> Dick

OK thanks, I looked up things in that direction,
and I found something useful, which seems to work.

Imports System.Net.Sockets

Imports System.Text

Public Class Form1

Private oTCPStream As Net.Sockets.NetworkStream

Private oTCP As New Net.Sockets.TcpClient()

Private bytWriting As [Byte]()

Private bytReading As Byte()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Try

TextBox1.Text = ""

oTCP.SendTimeout = 1500

oTCP.Connect("999.99.99.9", "259")

oTCPStream = oTCP.GetStream

TextBox1.Text = TextBox1.Text & ReadData() & vbCrLf

WriteData("myusername" & vbCrLf)

System.Threading.Thread.Sleep(500)

TextBox1.Text = TextBox1.Text & ReadData() & vbCrLf

WriteData("mypassword" & vbCrLf)

System.Threading.Thread.Sleep(1000)

TextBox1.Text = TextBox1.Text & ReadData() & vbCrLf

WriteData("1" & vbCrLf)

TextBox1.Text = TextBox1.Text & ReadData() & vbCrLf

oTCPStream.Close()

oTCP.Close()

MsgBox("connection ok")

Catch Err As Exception

MsgBox(Err.ToString)

End Try

End Sub

Private Function ReadData() As String

Dim sData As String

ReDim bytReading(oTCP.ReceiveBufferSize)

oTCPStream.Read(bytReading, 0, oTCP.ReceiveBufferSize)

sData = Trim(System.Text.Encoding.ASCII.GetString(bytReading))

ReadData = sData

End Function

Private Sub WriteData(ByVal sData As String)

bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)

oTCPStream.Write(bytWriting, 0, bytWriting.Length)

End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.