Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Communications (http://www.xtremevbtalk.com/-net-communications/)
-   -   Simple Telnet Client (http://www.xtremevbtalk.com/-net-communications/269691-simple-telnet-client.html)

joshjoneswas 08-29-2006 09:07 PM

Simple Telnet Client
 
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.

Anyone help a fellow out? Thanks!

wayneph 08-29-2006 09:51 PM

Here is something I found the other day. Note, that I've never used it, but it claims to work...
http://www.xtremevbtalk.com/-net-communications/269233-vb-unix-post1174455.html

joshjoneswas 08-29-2006 10:17 PM

Thank you. That almost got it.

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! :)

Any other suggestions Wayne?

dannyb 08-30-2006 07:51 AM

You could look at the MSDN forum wich talks about what your looking to do.
http://forums.microsoft.com/MSDN/Sho...40202&SiteID=1

wayneph 08-30-2006 09:12 AM

Quote:

Originally Posted by dannyb
You could look at the MSDN forum wich talks about what your looking to do.
http://forums.microsoft.com/MSDN/Sho...40202&SiteID=1

That points to the same link in my previous post. :)

Quote:

Originally Posted by joshjoneswas
I really don't understand why someone SOMEWHERE has not connected via telnet with anything in VS2005!

I'm sure someone has. It just looks like that they haven't posted anywhere with how they did it...

In the MS 101 Samples it looks like group 2 has a sockets example, but I haven't looked at it to see what it actually does...

joshjoneswas 08-30-2006 05:43 PM

I am looking into that one. It will take some dumbing down of the MSDN code I'll bet, but I'll hopefully figure it out.

Anyone heard of a C# example doing this over the last few years?

dilettante 09-09-2006 05:52 PM

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:

FetchDir.vbs
Code:
Set w3sock = CreateObject("socket.tcp") With w3sock .DoTelnetEmulation = True .TelnetEmulation = "TTY" .Host = "localhost:23" .Open .WaitFor "login:" .SendLine "YOURUSERID" .WaitFor "password:" .SendLine "YOURPASSWORD" .WaitFor ">" .SendLine "prompt $LREADY$G" .WaitFor "<READY>" .SendLine "dir c:\windows\repair" .WaitFor "<READY>" 'Parse echoed DIR line and trailing <READY> off results. WScript.Echo Split(Split(.Buffer, vbNewLine, 2)(1), "<READY>")(0) .Close End With 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:
Code:

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


joshjoneswas 09-09-2006 05:55 PM

That rocks! I had no idea there was a free one. I found several of them that wanted you to pay.

I am looking into this as we speak. I just wanted to thank you for catching the post and responding back to me!

DJeep 03-10-2008 12:50 PM

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

FleppSch 10-16-2015 03:17 AM

Hi,

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 ?

Thx
Regards
Philippe


All times are GMT -6. The time now is 09:59 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.