This is astonishing to me. I have scoured the net and not found any simple tutorials on using telnet in vb 2005!
I just realized tonight that I cannot create a batch file to telnet to a host in DOS then run a few commands after the login. (sort of a no duh moment since dos RUNS telnet..and then waits for it to get done so you can't script inside of that!)
I found a pretty neat telnet scripting tool by Albert Yale, but I'd rather do it behind the scenes since this will be a tool that we use at work where others will see it in action. Not too professional really with that third party implementation.
I just need it to connect to a telnet client, send the user name and password, then run a cmd file on that machine.
In VB6 I would always use a winsock control to do this. How is it done in vb 2005? I keep seeing sockets and other terms used while scouring.
I'm pretty good with C#, but didn't quite get all that the code was trying to do after VS2005 upgraded the example code. In fact, it didn't compile. But I tried to get the jist of it and it looks as though it is referencing system.net.sockets... so I will continue to mess around with that end of it...
I took off on the web again to see if I could find any telnet examples in C# and came up with no real quality results...shocking to me, truly.
Usually when I am browsing the net for something like this and it does not show up readily available, I find that I am approaching the problem at the wrong angle. But this one is different. I really don't understand why someone SOMEWHERE has not connected via telnet with anything in VS2005!
As a total .Net newbie I've recently been tearing my hair out once again trying to wrap my head around the way socket I/O is done. I've been amazed at the small number and poor quality of examples and descriptive text on the subject. That includes those from Microsoft.
Ignorant diatribe aside though, have you considered another solution? Say, something that doesn't require hacking together a program in VB.Net or C#?
For this very kind of thing I've found a handy free ActiveX component from Dimac to be just the ticket. I've used it for lots of little administrative tasks, from pinging HTTP servers to performing remote functions via Telnet just as you've described.
As I said, it's free - though they will make you register to get the download: Dimac Free Downloads. Once you have this installed you can handily script your way to a solution. Here's an example:
Set w3sock = CreateObject("socket.tcp")
.DoTelnetEmulation = True
.TelnetEmulation = "TTY"
.Host = "localhost:23"
.SendLine "prompt $LREADY$G"
.SendLine "dir c:\windows\repair"
'Parse echoed DIR line and trailing <READY> off results.
WScript.Echo Split(Split(.Buffer, vbNewLine, 2)(1), "<READY>")(0)
Set w3sock = Nothing
This is just a trivial example, but perhaps close to what you need. Run it from a command line or within a BAT/CMD file as in:
cscript //nologo FetchDir.vbs
My results look like:
Volume in drive C is System
Volume Serial Number is F8B2-FA88
Directory of c:\windows\repair
07/28/2006 05:39 PM <DIR> .
07/28/2006 05:39 PM <DIR> ..
08/23/2001 08:00 AM 1,688 autoexec.nt
07/28/2006 05:38 PM 2,577 config.nt
07/28/2006 05:43 PM 237,568 default
07/28/2006 05:43 PM 24,576 sam
07/28/2006 05:39 PM 787,668 secsetup.inf
07/28/2006 05:43 PM 28,672 security
07/28/2006 05:36 PM 208,626 setup.log
07/28/2006 05:43 PM 8,175,616 software
07/28/2006 05:43 PM 1,081,344 system
9 File(s) 10,548,335 bytes
2 Dir(s) 12,895,301,632 bytes free
Last edited by dilettante; 09-09-2006 at 05:55 PM.
I am using the vb2005 and DiMac w3sock and have a quick question. My command to show mac-address is stopping at the --More-- statement. How can I pass a space bar to get past the --More-- prompt. Or is there a way I can request the information that will ignore the prompt?
Thank you for your help.
I know this post has not been edited for more than 7 years but right now I'm stucked with the same problem as DJeep. My telnet session sometimes comes up with a "--More--" line and is waiting for a keypress. How can I solve/work around it ?