473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sending commands to a Telnet program

Ok, so I'm programming in Unix if that makes any difference. And I'm
doing:

system("telnet somehost.com 25");

But I can't figure out how to send a command to it. Like, for example,
I would like to send the helo command to the smpt port with this telnet
open. Does anyone here know how to? Thanks.

(kinda desired output)

# ./program

Telnetting...

helo
250 welcome.
mail from: wh******@something.org
250 ok.

etc...I think you get the idea that I would like to this inside my C
program.

-Zach

Jul 23 '05 #1
2 6250
On 2005-06-05, Zach Flynn <mo*******@hotmail.com> wrote:
Ok, so I'm programming in Unix if that makes any difference.
Yes, it does. It means that your question is topical in comp.unix.programmer
(but not here).
And I'm doing:

system("telnet somehost.com 25");

But I can't figure out how to send a command to it.
Perhaps it's because you're starting wrong.
Like, for example, I would like to send the helo command to the smpt port
with this telnet open. Does anyone here know how to? Thanks.


start with
man socket
and read the related pages.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #2
Zach Flynn wrote:
Ok, so I'm programming in Unix if that makes any difference. And I'm
doing:

system("telnet somehost.com 25");

But I can't figure out how to send a command to it. Like, for example,
I would like to send the helo command to the smpt port with this telnet
open. Does anyone here know how to? Thanks.

(kinda desired output)

# ./program

Telnetting...

helo
250 welcome.
mail from: wh******@something.org
250 ok.

etc...I think you get the idea that I would like to this inside my C
program.

-Zach


First, wrong newsgroup for this.

Second, you'll want to do roughly the following:
1) Open two pipes. (man 2 pipe)
2) Fork. (man 2 fork)
3) Close the unneeded ends of the pipes in each process. (man 2 close)
4) Use dup2 to set stdin and stdout to your pipes. (man 2 dup2)
5) In your child process, do something like execl("/bin/sh", "/bin/sh",
"-c", "telnet host port"). (man 3 execl)

Then you could read from the program and write to its stdin via your
pipes. Or if you were more comfortable, use fdopen to get FILE*'s to
read/write with instead.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to...
5
by: Greg Martz | last post by:
I'd like to do the following in C# and prefer using tcpclient rather than raw sockets... Connect to a unix box Login run date +%H%M%S retrieve the response. That's it, nothing more. This...
7
by: Rex Winn | last post by:
I've Googled until my eyes hurt looking for a way to issue Telnet commands from C# and cannot find anything but $300 libraries that encapsulate it for you. I don't want to be able to create a...
2
by: barry | last post by:
The code below is in a button but though there is no error message of any kind I am not getting the email which I am sending to myself. Any help would be appreciated. ...
3
by: mule | last post by:
hello all, I have a c# app that telnets into a router and issues a series of commands. All works great except I haven't figured out how to send a CTRL+C. I need this so I can kill a program that...
0
by: knowthediff | last post by:
Hello, I have a VS 2005 windows form app that I am creating. It uses Async socket to telnet which sends and receives commands. Everything seems to be working fine until I attempt to process a...
5
by: pbd22 | last post by:
Hi. Anybody know of any good code examples out there on how to take a telnet command and parse it? Thanks!
0
by: Graycon | last post by:
I am trying to reboot several devices on my private network through telnet. I wrote a vbs that does the operation but i cannot select any other window while it is running of the input will not go...
2
by: HTCGuy | last post by:
Hi, im building an application that has to run a series of simple telnet commands . login wget some links chmod some files exit The only thing Ive found sofar are massive fully function c#...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.