L
lanjf
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,我在编一个自动TELNET UNIX的程序,用clinetsocket进行Telnet协议的子
协商过程后,出现login:接着通过SENDBUF输入用户名,就没办法进行捕捉password了,求救
各位大侠,有没有什么办法,或者帮帮改程序.
unit telnet_unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Button1: TButton;
Button2: TButton;
procedure readfromhost(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const F_IAC=255;
//DO协商
const F_DO=253;
//DO NOT协商
const F_DONT=254;
//WILL 协商
const F_WILL=251;
//WILL NOT协商
const F_WONT=252;
const F_GOAHEAD=3;
const F_ECHO=1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var server:string;
begin
if ClientSocket1.Active then ClientSocket1.Active := False;
if InputQuery('连接至:', '地址:', Server) then
if Length(Server) > 0 then
with ClientSocket1 do
begin
Address := Server;
Active := True;
end;
end;
procedure TForm1.readfromhost(Sender:TObject;
Socket: TCustomWinSocket);
var
loginsend,passsend:boolean;
inbuffer:array[0..2048] of char;
reply:array[0..2] of char;
count,m_count,code:integer;
cmd,ch,nOpt:char;
m_string,cmdtounix:string;
begin
loginsend:=False;
passsend:=False;
count:=Socket.ReceiveBuf(InBuffer,High(InBuffer));
m_count:=0;
while (m_count<count) do
begin
ch:=InBuffer[m_count];
if (ch=char(F_IAC)) then
begin
m_count:=m_count+1;
cmd:=InBuffer[m_count];
if((cmd=char(F_DO))or(cmd=char(F_WILL))or(cmd=char(F_DONT))or(cmd=char(F_WONT))) then
begin
m_count:=m_count+1;
nOpt:=InBuffer[m_count];
if((nOpt=char(F_GOAHEAD))or
(nOpt=char(F_ECHO))) then
begin
if(cmd=char(F_DO)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_WILL);
reply[2]:=nOpt;
Socket.SendBuf(reply,Length(reply));
end;
if(cmd=char(F_WILL)) then begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_DO);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
end;
if((nOpt<>char(F_GOAHEAD))or(nOpt<>char(F_ECHO))) then
begin
if(cmd=char(F_DO)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_WONT);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
if(cmd=char(F_WILL)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_DONT);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
end;
end;
end; //end F_IAC
if(ch<>char(F_IAC)) then
begin
m_string:=m_string+ch;
end;
m_count:=m_count+1;
end;
//假设编程者知道Unix的LOGIN和PASSWORD
//showmessage(inttostr(length(m_string)));
if (Length(m_string)>0) then
begin
while ((Pos('login:',m_string)>0)and(not loginsend)) do
begin
cmdtounix:='root'+#10+#13;
code:=Socket.SendBuf(cmdtounix,6);
//showmessage(m_string);
showmessage(inttostr(pos('login:',m_string)));
loginsend:=True;
m_string:='';
end;
while ((Pos('assword:',m_string)>0)and(not passsend)) do
begin
showmessage(m_string);
cmdtounix:='rootndgs'+#10+#13;
code:=Socket.SendBuf(cmdtounix,10);
passsend:=True;
showmessage(inttostr(pos('login:',m_string)));
m_string:='';
end;
if ( Pos('#',m_string)>0) then
begin
cmdtounix:='mkdir /lanjianfe'+#13+#10;
code:=Socket.SendBuf(cmdtounix,Length(cmdtounix));
if code>0 then
begin
ClientSocket1.Active:=False;
//showmessage(m_string);
Close;
end;
end;
end;
//self.ClientSocket1.OnRead(self,self.clientsocket1.socket);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
self.clientsocket1.socket.read(2048);
showmessage('asfasfa');
end;
end.
协商过程后,出现login:接着通过SENDBUF输入用户名,就没办法进行捕捉password了,求救
各位大侠,有没有什么办法,或者帮帮改程序.
unit telnet_unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Button1: TButton;
Button2: TButton;
procedure readfromhost(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const F_IAC=255;
//DO协商
const F_DO=253;
//DO NOT协商
const F_DONT=254;
//WILL 协商
const F_WILL=251;
//WILL NOT协商
const F_WONT=252;
const F_GOAHEAD=3;
const F_ECHO=1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var server:string;
begin
if ClientSocket1.Active then ClientSocket1.Active := False;
if InputQuery('连接至:', '地址:', Server) then
if Length(Server) > 0 then
with ClientSocket1 do
begin
Address := Server;
Active := True;
end;
end;
procedure TForm1.readfromhost(Sender:TObject;
Socket: TCustomWinSocket);
var
loginsend,passsend:boolean;
inbuffer:array[0..2048] of char;
reply:array[0..2] of char;
count,m_count,code:integer;
cmd,ch,nOpt:char;
m_string,cmdtounix:string;
begin
loginsend:=False;
passsend:=False;
count:=Socket.ReceiveBuf(InBuffer,High(InBuffer));
m_count:=0;
while (m_count<count) do
begin
ch:=InBuffer[m_count];
if (ch=char(F_IAC)) then
begin
m_count:=m_count+1;
cmd:=InBuffer[m_count];
if((cmd=char(F_DO))or(cmd=char(F_WILL))or(cmd=char(F_DONT))or(cmd=char(F_WONT))) then
begin
m_count:=m_count+1;
nOpt:=InBuffer[m_count];
if((nOpt=char(F_GOAHEAD))or
(nOpt=char(F_ECHO))) then
begin
if(cmd=char(F_DO)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_WILL);
reply[2]:=nOpt;
Socket.SendBuf(reply,Length(reply));
end;
if(cmd=char(F_WILL)) then begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_DO);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
end;
if((nOpt<>char(F_GOAHEAD))or(nOpt<>char(F_ECHO))) then
begin
if(cmd=char(F_DO)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_WONT);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
if(cmd=char(F_WILL)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_DONT);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
end;
end;
end; //end F_IAC
if(ch<>char(F_IAC)) then
begin
m_string:=m_string+ch;
end;
m_count:=m_count+1;
end;
//假设编程者知道Unix的LOGIN和PASSWORD
//showmessage(inttostr(length(m_string)));
if (Length(m_string)>0) then
begin
while ((Pos('login:',m_string)>0)and(not loginsend)) do
begin
cmdtounix:='root'+#10+#13;
code:=Socket.SendBuf(cmdtounix,6);
//showmessage(m_string);
showmessage(inttostr(pos('login:',m_string)));
loginsend:=True;
m_string:='';
end;
while ((Pos('assword:',m_string)>0)and(not passsend)) do
begin
showmessage(m_string);
cmdtounix:='rootndgs'+#10+#13;
code:=Socket.SendBuf(cmdtounix,10);
passsend:=True;
showmessage(inttostr(pos('login:',m_string)));
m_string:='';
end;
if ( Pos('#',m_string)>0) then
begin
cmdtounix:='mkdir /lanjianfe'+#13+#10;
code:=Socket.SendBuf(cmdtounix,Length(cmdtounix));
if code>0 then
begin
ClientSocket1.Active:=False;
//showmessage(m_string);
Close;
end;
end;
end;
//self.ClientSocket1.OnRead(self,self.clientsocket1.socket);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
self.clientsocket1.socket.read(2048);
showmessage('asfasfa');
end;
end.