Re: Using port 23 and issuing telnet commands...
- From: "Picho" <SPAM_picho@xxxxxxxxxxxx>
- Date: Mon, 2 May 2005 20:10:20 +0300
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
>
>
.
- Follow-Ups:
- Re: Using port 23 and issuing telnet commands...
- From: Rex Winn
- Re: Using port 23 and issuing telnet commands...
- From: Rex Winn
- Re: Using port 23 and issuing telnet commands...
- References:
- Using port 23 and issuing telnet commands...
- From: Rex Winn
- Using port 23 and issuing telnet commands...
- Prev by Date: Re: Reflection and PropertyInfo
- Next by Date: Re: Required Field Validator fails to work on production
- Previous by thread: Using port 23 and issuing telnet commands...
- Next by thread: Re: Using port 23 and issuing telnet commands...
- Index(es):
Relevant Pages
|
Loading