Interactive Telnet

This is a discussion on Interactive Telnet within the C Programming forums, part of the General Programming Boards category; Hello all, I'm new to C/C++ and i'm looking for some good examples on interactive telnet code. Can somebody point ...

  1. #1
    Pure resulting insanity
    Join Date
    May 2005
    Posts
    2

    Interactive Telnet

    Hello all,

    I'm new to C/C++ and i'm looking for some good examples on interactive telnet code. Can somebody point me in the right direction to good real-world examples.

    I'm coming from a Perl/Expect background way of doing things, however I want to write something in C/C++ so I can interact through telnet to a Cisco router and perform a series of commands etc.

    Some advise too if you don't mind. From my Googling I've seemed to notice C/C++ programmers tend to like re-creating the wheel so to speak when coming to such types of programs, so they tend to build raw sockets etc to do this. Am I right in being lead to believe this? Isn't their an easier way like with Perl to include a module like NET::TELNET and just pass arguments through to the module that has been pre-written. I'm sure there must be something but I think for the most part I may not being searching for the right terms to pull good results.

    I guess in a nutshell I'm probably being lazy and I'm looking for some sort of good practical code example. Some of the C books I'm reading are good to get into the language however I don't seem to see many books on the networking side. Now before you mention D. Comer and Stevens books etc which I do know of I'm talking about books that deal with network applications through examples, not the setting up a basic tcp/upd server daemon type. There seem to be plenty of other books on various other topics except when it comes to networking.

    Anyway may be a bit short-sighted at the moment into this but I'm yearning for some direction and answers. I hope someone can help.

    Much obliged.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Is this code supposed to do something that your standard run-of-the-mill telnet client can't do? If you're not out to learn exactly how this works (i.e. re-inventing the wheel) then I don't understand why you don't just use a telnet client that already exists.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Pure resulting insanity
    Join Date
    May 2005
    Posts
    2
    Ok I don't think I came across clearly.

    I don't want to write a telnet client. I want to write a program that can use telnet to connect to a router. Then once it has connected to the router performing an expect-like sequence to login, then send various commands to be performed by the router.

    This is so I can automate certain tasks on the router.

    In Perl one can use the NET::TELNET module which saves you from writing all the necessary telnet code, and then you can use expect to perform the automated command sending. Now i'd like to do the same in C/C++ but just need some examples on this or a point in the right direction.

    Hope this is a bit clearer.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    First you will need to understand socket programming to make the connection to the telnet server. Then read the telnet rfc (http://www.faqs.org/rfcs/rfc854.html) to see how the telnet protocol works.
    Basically your program is going to connect to the server then do protocol negotiations and then in a loop get any output from the server and send anything that needs to be sent untill the program or server closes the connection or the connection is broken.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    And to simulate "expect", you will need at least two threads, a reader and a writer, maybe more. This is a bit of a rough project for a first shot at C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with telnet and tcp
    By hoAx in forum Windows Programming
    Replies: 11
    Last Post: 03-11-2008, 02:03 PM
  2. C Function Telnet Email
    By karcheee in forum C Programming
    Replies: 3
    Last Post: 07-25-2005, 11:39 AM
  3. C Execl Telnet
    By karcheee in forum C Programming
    Replies: 1
    Last Post: 04-26-2005, 02:31 PM
  4. telnet!!
    By bigB8210 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-13-2003, 05:09 PM
  5. Most Secure (SSH) Telnet Client for Programming
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 02-14-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21