473,750 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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******@someth ing.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 6268
On 2005-06-05, Zach Flynn <mo*******@hotm ail.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.progr ammer
(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******@someth ing.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
13998
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 this socket just like you would enter things on the keyboard if you telneted to this server). In a normal telnet session you can enter some commands which take a long time to complete, and they run in the background and you get the command line...
5
33879
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 shouldn't be too complicated, I thought... I have yet to find any examples of being able to do this.
7
14096
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 Telnet client. I just need to send a telnet request to a local IP address on a LAN issue a "c" then a "b" and stream back the text for internal use. The "c" changes sub-menus and the "b" is a switch to dump the status of a firewall. I need to issue...
2
2262
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. System.Web.Mail.SmtpMail.SmtpServer = "127.0.0.1" System.Web.Mail.SmtpMail.Send(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)
3
3136
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 tends to get hung. Thanks!
0
1508
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 command quickly. For example, I want to creata a script and run that script on the telnet window. For simpliciy lets say I would like to list directory contents 2 times in a row. I want to process "dir" two times. So, via code I send the dir...
5
8788
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
4846
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 into the telnet window created. I have begun to convert the code to C++ and am having problems I can get telnet to open to the ip address that I want but do not know how to pass any commands to it. I have read about 30 different website and people...
2
2367
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# telnet clients which i have no hope of integrating into my project .Can anyone tell me where i can get a free telnet client that can load scripts without user input or a way to achive the above without a massive telnet client ? thanks
0
9002
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8840
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9399
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9259
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6817
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6083
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.