473,714 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Telnet commands using C# and tcpclient

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.
Any suggestions?

Thanks!
Greg
Nov 15 '05 #1
5 33866
<FrameworkSDK>\ Samples\Applica tions\WinTalk is sample in MSDN, it provides
demo of Socket wrapped class.
No doubt you can do following that way, yet perhaps simpler way does exist.

"Greg Martz" <a-*****@microsoft .com>
??????:MP****** *************** ***@msnews.micr osoft.com...
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.
Any suggestions?

Thanks!
Greg

Nov 15 '05 #2
If you are looking for a decent book that covers Sockets and associated
classes try to pick up a copy of "Profession al .NET Network Programming"
from (now defunct) Wrox Press. (ISBN 1-86100-735-3)
DL
"Greg Martz" <a-*****@microsoft .com> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
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.
Any suggestions?

Thanks!
Greg

Nov 15 '05 #3
Dave Loynd writes:
...from (now defunct) Wrox Press.


Do you know if this means that books they had in the pipeline are dead? In
particular I expected to see their "Profession al C# Design Patterns Applied"
(or whatever it was going to be called) last month. Is someone else taking
over their properties?

Michael Roper
Nov 15 '05 #4
Greg Martz <a-*****@microsoft .com> wrote in message news:<MP******* *************** **@msnews.micro soft.com>...
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.
Any suggestions?

Greg -

I guess it depends on how you define "complicate d". Connecting to
the Unix box is easy, trying to follow the Telnet protocol will be
your challenge.

The basics to get you connected to the server are easy:

TcpClient sock = new TcpClient("remo tehostIP", 23);
NetworkStream ns = sock.GetStream( );
byte[] data = new byte[1024];
int recv = ns.Read(data, 0, data.Length);

However, what you will see returned in the data array will not be
what you expect to see. When a Telnet session is first established,
the host and client send a series of negotiation packets back and
forth to determine what capabilities are supported by each (see RFC
854). The first packet of data received from the host will contain a
byte stream containing the negotiation request. It's your job to
correctly answer the negotiation with an appropriate byte stream
before you will see the login message text from the server.

If you are always connecting to the same Unix box, you might be
able to capture a Telnet session using a sniffer (or the WinPcap
analyzer program on your PC), then duplicate the session in your
connection. Usually there are two or three back-and-forth sessions
before the host sends the login message text. Once you see that you
are mostly home free (although Telnet does allow for the host to
renegotiate during the session, so watch out for that).

Hope this helps point you in the right direction to solve your
problem. Good luck in your network programming.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Nov 15 '05 #5
In article <cc************ **************@ posting.google. com>,
ri*******@juno. com says...
Greg Martz <a-*****@microsoft .com> wrote in message news:<MP******* *************** **@msnews.micro soft.com>...
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.
Any suggestions?

Greg -

I guess it depends on how you define "complicate d". Connecting to
the Unix box is easy, trying to follow the Telnet protocol will be
your challenge.

The basics to get you connected to the server are easy:

TcpClient sock = new TcpClient("remo tehostIP", 23);
NetworkStream ns = sock.GetStream( );
byte[] data = new byte[1024];
int recv = ns.Read(data, 0, data.Length);

However, what you will see returned in the data array will not be
what you expect to see. When a Telnet session is first established,
the host and client send a series of negotiation packets back and
forth to determine what capabilities are supported by each (see RFC
854). The first packet of data received from the host will contain a
byte stream containing the negotiation request. It's your job to
correctly answer the negotiation with an appropriate byte stream
before you will see the login message text from the server.

That's what I was doing all right. And yes, I noticed the data that I
was getting back, just didn't know it was a negotiation routine. I
don't really want to write an entire telnet client just to do this
simple task, so I'll look at trying a different way. Thanks for your
assistance!

Thanks!
Greg
Nov 15 '05 #6

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

Similar topics

7
14092
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
15779
by: b00x | last post by:
Hi, I'm trying to develop a script that I can reuse to run remote commands on multiple UNIX servers via telnet. I've tried various php scripts after googling for a good 5 or so hours, but found no luck. I've created a script (suprisingly) similar to the on found an old post from 2001...
0
3850
by: goroth | last post by:
I am trying to create a telnet client that will connect to several of my network devices on campus and change settings on the devices. So far I can connect with the code below, but I can't seem to get the correct return data from the device. Sometimes I get about 100 bytes and other times I get 3000 bytes. I even put a thread sleep but that still give me different return data from different devices. I know I am going to have to use an...
0
1320
by: john.kramer | last post by:
I need a VB.NET app that allows me to connect to a device using telnet, send two commands (the second of which terminates the connection), then confirm that the connection is terminated. If I telnet normally through Windows, I connect, hit the <ENTERat the first prompt, wait for the second prompt, then press 9 and then <ENTERagain. At this point te device reboots and I get disconnected. The code I've attempted (but failed at) is below. I'm...
2
6802
by: Screaming Eagles 101 | last post by:
Hi, I looked and found a lot of different code regarding send/receiving input/output to a command window, but none helped me so far. I would like to start a process with telnet a bit like this myProcess.StartInfo.FileName = "telnet.exe" myProcess.StartInfo.Arguments = " -a 199.99.99.99 299" ' (IP and port) = this works....
6
6147
by: =?Utf-8?B?U2hhcmllZg==?= | last post by:
Dear All, I must write a client program in C# which will communicate with a switch throught telnet. When I create a socket connection on port 22, the switch responds with some text and at the end with some unreadable characters. I found out that the operating system of the switch is redhat and the protocol = SSH-2.0-openssh_3.9p1. My problem:
5
8785
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!
4
2866
by: pbd22 | last post by:
Hi I am making my way through a windows service that accepts custom telnet commands as strings and then parses the string and redirects it. This would be a custom string sent via telnet. So, I need to prompt the user for input and then capture that imput, parse it into a form that is readable (strings in
9
19177
by: pbd22 | last post by:
Hi. Does anybody know how to issue a clear screen command like DOS "cls" in a telnet session? Thanks!
0
8796
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
8704
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
9307
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...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6627
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
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2105
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.