Re: Using port 23 and issuing telnet commands...



Rex,

this is a method I once used to execute shell commands on a unix machine.
look at the structure and I think you can start from there.

this method is old so it might not be 'elegant' or 'clean' so put those
things aside.

<Code>
public bool Exec(string Command, string Host, int Port,string UN, string
PWD)

{

TcpClient client = null;

byte[] read = new byte[128];

byte[] send = new byte[128];

int bytes;

string data;

try

{

client = new TcpClient(Host,Port);

}

catch (Exception ex) //connection problem

{

throw ex;

}

NetworkStream stream = client.GetStream();

send = Encoding.ASCII.GetBytes(UN);

stream.Write(send,0,send.Length);

bytes = stream.Read(read, 0, read.Length);

data = Encoding.ASCII.GetString(read);


send = Encoding.ASCII.GetBytes(PWD);

stream.Write(send,0,send.Length);

bytes = stream.Read(read, 0, read.Length);

data = Encoding.ASCII.GetString(read);

send = Encoding.ASCII.GetBytes(Command);

stream.Write(send,0,send.Length);


bytes = stream.Read(read, 0, read.Length);

string retval = Encoding.ASCII.GetString(read);


stream.Close();

client.Close();


if (retval[0]=='0')

return true;

else

return false;

}

</Code>



Picho

"Rex Winn" <rex@xxxxxxxxxxxxx> wrote in message
news:151500632506284565781250@xxxxxxxxxxxxxxxxxxxxxxx
> 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 the
> "b" every second and capture that stream of text that would
> go to a telnet client and use it internally. Is there a way that
> C# can do this programmatically? System.Diagnostices.Process
> is not the solution that I am aware of. Maybe there's a switch
> for it to hide the telnet window and wrap it but I couldn't find
> anything to support that.
>
> - Rex
>
>


.



Relevant Pages

  • Re: Telnet via Expect from Windows to Windows (Text is not displayed correctly)
    ... >the Windows Shell is not the Problem. ... >the Windows 2000 Telnet Daemon is configured correctly at that point. ... The Windows Telnet Client is not displaying everything ... >correctly when it is receiving its commands from expect, ...
    (comp.lang.tcl)
  • Re: MS telnet w/ alternate terminal type?
    ... up their logons at the office or when using other telnet clients. ... emulation in use by the telnet client -- except when that telnet client is ... Using the ANSI emulation on a MS telnet client ... And if I do manually change the TERM value from inside AIX, ...
    (comp.unix.aix)
  • Re: Disable SSH authentication
    ... I interpreted that sentence of chaoson to mean "type in user ... some commands on the remote machine ... I remember to all of you that rsh or telnet are an input/output ... and interprets commands send to it through a ...
    (SSH)
  • Re: MS telnet w/ alternate terminal type?
    ... be -- to log in and use the local telnet client to get limited functionality ... It allows telnet connections and you can specify the emulation. ... And if I do manually change the TERM value from inside AIX, ...
    (comp.unix.aix)
  • Re: TN3270 *from* a host??
    ... It allows the end user to send commands to the TELNET server, ... "Reverting to linemode" implies that, somehow, the SNA session ...
    (bit.listserv.ibm-main)

Loading