Do a telnet action using Vb.net
Hi,
I'm writing a program to connect to telnet server and execute a command...
I 'm getting this error Value of type 'String' cannot be converted to 'System.Security.SecureString'.
Here is my code
Code Snippet
Dim tnAs Process
tn =New Process
tn.StartInfo.FileName ="telnet.exe"
tn.StartInfo.Arguments ="10.0.0.1"
tn.StartInfo.UserName ="user"
tn.StartInfo.Password ="pass"
tn.Start()
Can someone help me?
Dim pw As String = "pass"
Dim ss As New System.Security.SecureString
For I As Byte = 0 To pw.Length - 1
ss.InsertAt(I, pw.Substring(I, 1))
Next
Dim tn As New Process
tn.StartInfo.FileName = "telnet.exe"
tn.StartInfo.UseShellExecute = False
tn.StartInfo.Arguments = "10.0.0.1"
tn.StartInfo.UserName = "user"
tn.StartInfo.Password = ss
tn.Start()
But please know this is not really secure. Anyone could use notepad on your assembly and figure out your password.
Thanks for the reply...That work, but now i got a login error incorrect password
There is another way to send commands to command line?
we need to know what telnet.exe requires.
Can you login manually?
Yes, using command prompt i can login..
telnet 10.0.0.1
login: user
password: pass
kill -HUP `cat /var/run/ppp0.pid`
I want to execute this commands to connect to my router and reboot Internet connection.
I believe so......
Telnet has command line prompts:
C:\>telnet /?
telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]]
-a Attempt automatic logon. Same as -l option except uses
the currently logged on user's name.
-e Escape character to enter telnet client prompt.
-f File name for client side logging
-l Specifies the user name to log in with on the remote system.
Requires that the remote system support the TELNET ENVIRON option.
-t Specifies terminal type.
Supported term types are vt100, vt52, ansi and vtnt only.
host Specifies the hostname or IP address of the remote computer
to connect to.
port Specifies a port number or service name.
but I do not see a password argument....... anywhere
I believe so......
Telnet has command line prompts:
C:\>telnet /?
telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]]
-a Attempt automatic logon. Same as -l option except uses
the currently logged on user's name.
-e Escape character to enter telnet client prompt.
-f File name for client side logging
-l Specifies the user name to log in with on the remote system.
Requires that the remote system support the TELNET ENVIRON option.
-t Specifies terminal type.
Supported term types are vt100, vt52, ansi and vtnt only.
host Specifies the hostname or IP address of the remote computer
to connect to.
port Specifies a port number or service name.
But I do not see a password argument....... anywhere. You may have some luck with a batch file using that escape char argument to allow the batach file a feed the program a password.
See if you can start it with a batchfile. I think you may to define an it escape character, after starting it defining an escape character the batch file should use the escape character defining a password. If you can get it to work with a batch file, you cas start the batch file from a program.
have you seen this?
http://technet2.microsoft.com/WindowsServer/en/Library/ddf8b035-9035-475c-ae50-1d97bde83dba1033.mspx
i tried with a bat file but it don't worked..

i need to now how to send a command to the command line using vb console...
Are you using a form or a console App? Either way it should be the same.
Do you have an expample of a single command line that logs you on?
Could I see your batch file?
console app.
The only way i found to using bat file to conect to telnet is using
Telnet Scripting Tool
--REBOOT.TXT-
10.0.0.1
WAIT "BusyBox on (none) login:"
SEND "MYUSER\m"
WAIT "Password:"
SEND "MYPASS\m"
WAIT "#"
SEND "kill -HUP `cat /var/run/ppp0.pid`\m"
WAIT "#"
--and use this command..
c:\tst\TST10.exe /r:reboot.txt
this works with notepad:
Dim tn As New Process tn.StartInfo.FileName =
"notepad.exe" tn.StartInfo.Arguments =
"c:\temp\deleteme.text" tn.Start()
so this should workk with telnet
Dim tn As New Process tn.StartInfo.FileName =
"telenet.exe" tn.StartInfo.Arguments =
"/r:reboot.txt
" tn.Start()
I have a feeling you will definitely need a path specifier for reboot.txt
thx this worked