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

  • Thread starter Screaming Eagles 101
  • Start date
S

Screaming Eagles 101

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...


--
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!]
----------------------------------------------------------------
 
D

Dick Grier

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

--
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.
 
S

Screaming Eagles 101

--
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 said:
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

--
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.


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top