Thread: Help - system(telnet) on WinXP (ssh too)

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Help - system(telnet) on WinXP (ssh too)

    Hi
    I am very new at this. Did some C 15 years ago but not an expert, then or now
    Have Watcom C free compiler on XP.

    Trying to write something (C/PERL/EXPECT ?) that will telnet to a (list of later) device (cisco router) pass my username and password to the device to log in, do some things by passing commands to the telnet window, and, if possible read the screen generated, and decide what to do or not do from that screen. I have a small program telneting to one box working with system("telnet x.x.x.x"); and I can initialize and define char variables with
    char *name; and
    name="smith";

    but I am stuck after this !

    example:
    telnet a.b.c.d
    pass name and password
    enable
    pass password
    show ver
    if screen shows IOS is version (have to search for a string) xxx, then do these commands, else, do some others.

    Also, does Watcom (or?) have their own telnet or ssh so I don't need to use the system's ?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Well, Telnet is just a raw text-based protocol. Perhaps build your own simple "client"? And write your own telnet doolacky program,

    See: http://en.wikipedia.org/wiki/TELNET

    I would say this is easier & cleaner than trying to invoke Microsofts Telnet client and read from it...

    Look at Winsock (since your on Windows, MSDN is also going to be a valuable guide.)

    hth.
    Last edited by zacs7; 04-11-2007 at 06:50 AM.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Can't reinvent the wheel

    Telnet is going away in our environment, so writing a telnet client which I can't take the time learning, is not a good way to spend my time. Telnet is being replaced by ssh, so if I were to write a client, it would be ssh. It would be more likely for me to get a PO approved for someone to write what I need than spend months doing it.

    I have hundreds of devices that I can either snmp-configure (which works most of the time) or write something in C or PERL/expect/tcl? I'd prefer C, but I need help obviously. I know my C abilities, and even 15 years ago when I was using Borland C, I was a novice even though I wrote the fastest file finder I knew of. I used to write assy too, but better at reading a PC's BIOS than writing it.

    I have to use MSoft's telnet for now, and I will need a command line ssh too. Seems to me someone must have written a real nice telnet/ssh client !

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Small steps along the way

    I was -just- about to post that I figured out putty.exe can be used command line....

    However, I still need to do a lot of other things....C or PERL or ?

    Before I even get to putty I need to determine if the host can run ssh, by telneting then...

    I need to tell putty to ignore the fact that the host key is not in the registry (press left arrow then enter).

    Then I need to send a password to putty.exe, etc etc...

    SMALLSTEP:
    How can I send a username and password to Win-telnet used as system ("telnet host"); ?
    BTW, these are mostly cisco devices, and 'telnet host -l username' does not work.
    Last edited by Mikey; 04-11-2007 at 08:01 AM.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Rather than writting a program to control another program, Perhaps edit Putty? After all it is open source... You could easily edit it do get your job done.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    From the putty help
    Quote Originally Posted by putty help
    Plink (PuTTY Link) is a command-line connection tool similar to UNIX ssh. It is mostly used for automated operations, such as making CVS access a repository on a remote server.
    > However, I still need to do a lot of other things....C or PERL or ?
    Unless you don't know perl at all, or are a C wizard, I'd say perl.

    It seems on the face of it that you'll be doing an awful lot of string work, which is super basic stuff in perl, but the same thing in C can be tedious and error prone. Once you've gotten over the initial "hump" of the perl "camel" book, you should be able to do quite a lot quite quickly.

    Also, you might also find something which goes some way to solving the problem here - http://www.cpan.org/
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Sounds fairly easy. Use netcat to communicate with the remote host, and expect to control the session. Both tools are available on practically any platform.

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Sounds ez

    I'm not keen on perl but after reading for the past 3 hours at perl.org I have yet to find a way to call telnet and pass parameters to it. I'd prefer C. Perl seems to be about the same level as BASIC...

  10. #10
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    Perl seems to be about the same level as BASIC...
    How do you figure that?

  11. #11
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Mikey View Post
    I'm not keen on perl but after reading for the past 3 hours at perl.org I have yet to find a way to call telnet and pass parameters to it. I'd prefer C. Perl seems to be about the same level as BASIC...
    There's sure nothing like spending 3 hours investigating an entirely new language when the problem could be solved in ten minutes using the tools I mentioned...

  12. #12
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Oops...not to start a war :)

    I see perl as, not C, not assy, not machine language (1/0)...and like other higher level languages which can -almost- do whatever it is you need, perl/they have loads of extensions, more libraries of functions that might do what you need, all for the same reason is that they don't interact at a low enough level to be able to really do almost everything, like C does. BASIC I see the same way as perl. Just MHO.

  13. #13
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    You won't start a war with me, I'm not anal about that kind of stuff. I just wanted to know what your reasoning was because I'd never heard that comparison before.

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Here's the problem - you're a carpenter, and the only tool in your toolbox is a hammer.

    Unable to choose the right tool, you continue to bludgeon the task until it roughly fits the parameters of the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Win tnt and putty/ssh are fine

    I should point out again that I am not a 'programmer' per se...my goal is to get 500 devices configured, not build the roads so UPS can get them to their destination When netcat is suggested it just puts me further behind as I try to download it, recfg my antivirus so it won't boot it off (may not be possible) and then I need to learn expect too...

    I am 'back to C' - how can I use windows telnet, and 'win' putty.exe, and pass parameters to them ? Please remember I'm a novice and the learning curve is always steep in the beginning like any language. I don't know how to use expect within a C program even...sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ssh daemon question
    By Overworked_PhD in forum Linux Programming
    Replies: 4
    Last Post: 07-07-2009, 11:44 AM
  2. Opening a telnet or SSH connection
    By ac251404 in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2007, 09:17 AM
  3. SSH tunnel
    By kastrup_carioca in forum C Programming
    Replies: 10
    Last Post: 01-18-2006, 04:29 PM
  4. Dialog opens properly in winxp, but Freezes in win98se
    By hanhao in forum C++ Programming
    Replies: 4
    Last Post: 07-10-2005, 04:46 AM
  5. problem: online on winxp and linux red hat
    By gemini_shooter in forum Linux Programming
    Replies: 5
    Last Post: 05-29-2005, 02:14 PM