www.pudn.com > iproute.rar > unit1.pas


unit unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, ExtCtrls, IdStack, WinSkinData, IdBaseComponent, 
  IdComponent, IdIPWatch; 
 
type 
  TIpCount=record 
  ip:string; 
  count:Integer; 
end; 
  strecord=array of TIpCount; 
 
type 
  TSetThread = class(TThread) 
  private 
    Succeed2:Smallint; 
    FTip: string; 
    FTch,FTsock: integer; 
    FTg:strecord; 
    FTs:TStringList; 
  protected 
    procedure Execute; override; 
    procedure MyTerminate(Sender:Tobject); 
  public 
    FInfoForm:TForm; 
 
    constructor Create(FSuspend: Boolean;ip:string;sock,Ach:integer) ; 
  end; 
 
type 
  TForm8 = class(TForm) 
    Panel1: TPanel; 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Label5: TLabel; 
    Button1: TButton; 
    Edit1: TEdit; 
    Edit2: TEdit; 
    Edit3: TEdit; 
    Button2: TButton; 
    Button3: TButton; 
    Button4: TButton; 
    Button5: TButton; 
    Button6: TButton; 
    Edit4: TEdit; 
    Edit5: TEdit; 
    Button7: TButton; 
    RadioButton1: TRadioButton; 
    RadioButton2: TRadioButton; 
    Label6: TLabel; 
    SkinData1: TSkinData; 
    Label7: TLabel; 
    IdIPWatch1: TIdIPWatch; 
    CheckBox1: TCheckBox; 
    Timer1: TTimer; 
    Timer2: TTimer; 
    procedure Button1Click(Sender: TObject); 
    procedure RadioButton1Click(Sender: TObject); 
    procedure RadioButton2Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
    procedure Button6Click(Sender: TObject); 
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 
    procedure Button5Click(Sender: TObject); 
    procedure Button3Click(Sender: TObject); 
    procedure Button4Click(Sender: TObject); 
    procedure Button7Click(Sender: TObject); 
    procedure CheckBox1Click(Sender: TObject); 
    procedure Timer1Timer(Sender: TObject); 
    procedure Timer2Timer(Sender: TObject); 
  private 
 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
function tel_conn_0(ip:PChar;var sock:integer;user:PChar;pass:PChar;pass0:PChar):integer; 
function tel_cut_0(ip:PChar;sock:integer):integer;//断开连接 
function addroute_0(ip:PChar;sock:integer;id:integer;DestinaIP:String;DestinaMask:string;nexthop:String):integer;   //添加删除路由 
function saveconfig_0(ip:PChar;sock:integer):integer;  //保存配置 
procedure get_ip_0(ip:PChar;sock:integer;var Ag:strecord); 
function run_command_get_0(ip, commd: pchar; sock: integer): TStringList; 
function page_open_0(str:string):TStringList; 
 
function tel_conn_1(ip:PChar;var sock:integer;user:PChar;pass:PChar;pass0:PChar):integer;  //连接    1:连接成功 
function tel_cut_1(ip:PChar;sock:integer):integer;//断开连接 
function addroute_1(ip:PChar;sock:integer;id:integer;DestinaIP:String;DestinaMask:string;nexthop:String):integer;   //添加删除路由 
function saveconfig_1(ip:PChar;sock:integer):integer;  //保存配置 
procedure get_ip_1(ip:PChar;sock:integer;var Ag:strecord); 
function run_command_get_1(ip, commd: pchar; sock: integer): TStringList; 
function page_open_1(str:string):TStringList; 
 
 
procedure Arraydx(var Ag:strecord); 
procedure tdlcsip(Aoper: String); 
 
var 
  Form8: TForm8; 
  ch:Integer; 
  Fsock:integer; 
  slist:TStringList; 
  slist1:TStringList; 
  autex,undoautex:Boolean; 
 
implementation 
 
uses StrUtils; 
 
{$R *.dfm} 
 
function telnet_connect(const dest_ip:pchar;port:Cardinal;devicetype:integer):integer;stdcall; 
external 'devicemonitor.dll'; 
function new_do_command(sock:integer;const dest_ip:pchar;const cmdline:pchar):boolean;stdcall; 
external'devicemonitor.dll'; 
function ReadResult(sock:integer;const dest_ip:PChar;result_buf:PChar;buflen:integer):Boolean;stdcall; 
external'devicemonitor.dll'; 
function Bak_Config(str,filename:string):integer;stdcall; 
external 'BakConfig.dll'; 
 
procedure Arraydx(var Ag:strecord); 
var 
  fg1:strecord; 
  count,i,j:Integer; 
  ip:String; 
  temp:TIpCount; 
  ex:Boolean; 
begin 
  fg1:=Ag; 
  for i := High(fg1) downto  Low(fg1)+1 do 
  begin 
    ex:=False; 
    for j := High(fg1) downto  High(fg1)-i+1 do 
    if fg1[j].count>fg1[j-1].count then 
    begin 
      temp:=fg1[j]; 
      fg1[j]:=fg1[j-1]; 
      fg1[j-1]:=temp; 
      ex:=True; 
    end; 
    if not ex then Break; 
  end; 
  Ag:=fg1; 
end; 
 
function tel_conn_0(ip:PChar;var sock:integer;user:PChar;pass:PChar;pass0:PChar):integer;  //连接    1:连接成功 
var                                                                                        //2:密码错误 
  result_buf:pchar;                                                                        //0:连接失败 
  buflen:integer; 
  str,cc:String; 
  strlist:TStringList; 
  ifsucc:Boolean; 
begin 
  sock:=telnet_connect(ip,23,1); 
  if sock <>-1 then 
  begin 
    //Sleep(500); 
    buflen:=1024*16; 
    result_buf:=AllocMem(buflen*sizeof(char)); 
    str:=''; 
    while True do 
    begin 
      Sleep(100); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
          str:=str+string(result_buf) 
      else 
        Break; 
      cc:=RightStr(str,2); 
      if cc=': ' then 
        Break; 
    end; 
 
    if RightStr(str,10)='Username: ' then 
      if not new_do_command(sock,ip,user) then 
      begin 
        Result:=0; 
        Exit; 
      end; 
 
 
 
    if new_do_command(sock,ip,pass) then 
    begin 
    Sleep(500); 
      if new_do_command(sock,ip,'enable') then 
      begin 
      Sleep(500); 
        if new_do_command(sock,ip,pass0) then 
        begin 
         Sleep(500); 
         ReadResult(sock,ip,result_buf,buflen); 
         str:=string(result_buf); 
         strlist:=page_open_0(str); 
         str:=strlist.Strings[strlist.count-1]; 
         if Copy(str,length(str),1)='#' then 
          Result:=1 
         else 
          Result:=0; 
         FreeMem(result_buf,1024*16); 
         strlist.Free; 
        end 
        else 
          Result:=0; 
      end 
      else 
        Result:=0; 
     end 
     else 
      Result:=0; 
    end 
    else 
    Result:=0; 
end; 
 
 
function tel_conn_1(ip:PChar;var sock:integer;user:PChar;pass:PChar;pass0:PChar):integer;  //连接    1:连接成功 
var 
  result_buf:pchar; 
  buflen:integer; 
  str,cc:String; 
  strlist:TStringList; 
  ifsucc:Boolean; 
begin 
  sock:=telnet_connect(ip,23,1); 
  if sock <>-1 then 
  begin 
     buflen:=1024*16; 
     result_buf:=AllocMem(buflen*sizeof(char)); 
    str:=''; 
    while True do 
    begin 
      Sleep(100); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
          str:=str+string(result_buf) 
      else 
        Break; 
      cc:=RightStr(str,1); 
      if cc=':' then 
        Break; 
    end; 
 
    if RightStr(str,9)='Username:' then 
      if not new_do_command(sock,ip,user) then 
      begin 
        Result:=0; 
        Exit; 
      end; 
 
 
    if new_do_command(sock,ip,pass) then 
    begin 
    Sleep(500); 
      if new_do_command(sock,ip,'super') then 
      begin 
      Sleep(500); 
        if new_do_command(sock,ip,pass0) then 
        begin 
         Sleep(500); 
         ReadResult(sock,ip,result_buf,buflen); 
         str:=string(result_buf); 
 
         strlist:=page_open_1(str); 
         str:=strlist.Strings[strlist.count-1]; 
         if (Copy(str,0,1)='<')and(Copy(str,length(str),1)='>') then 
          Result:=1 
         else 
          Result:=0; 
         FreeMem(result_buf,1024*16); 
         strlist.Free; 
        end 
          else 
          Result:=0; 
      end 
      else 
        Result:=0; 
     end 
      else 
      Result:=0; 
    end 
    else 
    Result:=0; 
end; 
 
 
function run_command_get_1(ip, commd: pchar; sock: integer): TStringList; 
var 
  resu_strlist:TStringList; 
  result_buf:pchar; 
  buflen,i:integer; 
  str,s,ss:String; 
  c:pchar; 
  ifsucc:Boolean; 
  cc,w:string; 
  str_1:String; 
begin 
  if  new_do_command(sock,ip,commd) then 
  begin 
    buflen:=1024*16; 
    result_buf:=AllocMem(buflen*sizeof(char)); 
 
    while True do 
    begin 
      Sleep(100); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
          str:=str+string(result_buf) 
      else 
        Break; 
      w:=''; 
      w:=RightStr(str,16); 
      cc:=RightStr(str,1); 
      if (w='  ---- More ----')or (cc='>') or (cc=']') then 
        Break; 
    end; 
  //  log_w(str,string(commd)); 
    s:=RightStr(str,16); 
    ss:='  ---- More ----'; 
    c:=' '; 
 
    while s=ss do 
    begin 
      if new_do_command(sock,ip,c) then 
         begin 
         str_1:=''; 
 
            while True do 
              begin 
                Sleep(100); 
 
                ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
                if ifsucc then 
                  str_1:=str_1+string(result_buf) 
                else 
                  Break; 
                w:=''; 
                w:=RightStr(str_1,16); 
                cc:=RightStr(str_1,1); 
                if (w='  ---- More ----')or (cc='>') or (cc=']') then 
                  Break; 
              end; 
 
         end; 
      str:=str+str_1; 
      s:=RightStr(str,16); 
     end; 
//    log_w(str,string(commd)+'.text'); 
    resu_strlist:=page_open_1(str); 
    FreeMem(result_buf,1024*16); 
    for i := 0 to resu_strlist.Count-1 do 
    if Copy(resu_strlist.Strings[i],1,16)='  ---- More ----' then 
      resu_strlist.Strings[i]:=' '+Trim(MidStr(resu_strlist.Strings[i],17,length(resu_strlist.Strings[i]))); 
//    log_w(resu_strlist.Text,string(commd)+'.text'); 
    Result:=resu_strlist; 
  end; 
end; 
 
function page_open_1(str:string):TStringList; 
var 
  s:string; 
  i:integer; 
  strlist:TStringList; 
begin 
  strlist:=TStringList.Create; 
  while (str[1]=#$D)or(str[1]=#$A)do Delete(str,1,1); 
  i:=length(str); 
  while (str[i]=#$D)or(str[i]=#$A)do 
  begin 
   Delete(str,i-1,i); 
   i:=length(str); 
  end; 
  s:=''; 
  while Pos(#$D#$A,str)<>0 do 
  begin 
    s:=LeftStr(str,pos(#$D#$A,str)-1); 
    strlist.Add(s); 
    str:=MidStr(str,pos(#$D#$A,str)+2,length(str)); 
  end; 
  strlist.Add(str); 
  Result:=strlist; 
end; 
 
 
 
procedure get_ip_1(ip:PChar;sock:integer;var Ag:strecord); 
var 
  pcommd:PChar; 
  filee:TStringList; 
  i,j:Integer; 
  s,ss:String; 
  Fip:string; 
  strt:string; 
  intt:Integer; 
  ex:Boolean; 
begin 
  filee:=TStringList.Create; 
  pcommd:=pchar('display nat sess'); 
  filee:=run_command_get_1(ip,pcommd,sock); 
  for i := 0 to filee.Count-1 do 
  begin 
    ss:=trim(filee.Strings[i]); 
    strt:=trim(LeftStr(ss,pos(' ',ss)-1)); 
    try 
      intt:=StrToInt(strt); 
    except 
      Continue; 
    end; 
    ss:=trim(MidBStr(ss,pos(' ',ss)+1,length(ss))); 
    ss:=trim(MidBStr(ss,pos(' ',ss)+1,length(ss))); 
    ss:=trim(MidBStr(ss,pos(' ',ss)+1,length(ss))); 
    fip:=trim(LeftBStr(ss,pos(' ',ss)-1)); 
    ex:=False; 
    for j := 0 to Length(ag)-1 do 
    begin 
      if Ag[j].ip=Fip then 
      begin 
        Ag[j].count:=Ag[j].count+1; 
        ex:=True; 
        Break; 
      end; 
    end; 
    if not ex then 
    begin 
      SetLength(Ag,length(Ag)+1); 
      Ag[length(Ag)-1].ip:=Fip; 
      Ag[length(Ag)-1].count:=1; 
    end; 
  end; 
  filee.Destroy; 
end; 
 
 
function saveconfig_1(ip:PChar;sock:integer):integer;  //保存配置 
var 
  pcommd:PChar; 
  result_buf:pchar; 
  buflen:integer; 
  ifsucc:Boolean; 
  str,cc:String; 
begin 
  buflen:=1024*16; 
  result_buf:=AllocMem(buflen*sizeof(char)); 
  pcommd:=pchar('save'); 
  new_do_command(sock,ip,pcommd); 
//  Sleep(100); 
  while True do 
    begin 
      Sleep(100); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
        str:=str+string(result_buf) 
      else 
        Break; 
      cc:=RightStr(str,1); 
      if cc=']' then 
        Break; 
    end; 
 
  pcommd:=pchar('y'); 
  new_do_command(sock,ip,pcommd); 
  while True do 
    begin 
      Sleep(10000); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
        str:=str+string(result_buf) 
      else 
        Break; 
      cc:=RightStr(str,1); 
      if cc='>' then 
        Break; 
    end; 
  //if Pos('successfully',str)>0 then 
    Result:=1 ; 
 // else 
  //  Result:=0; 
  FreeMem(result_buf,1024*16); 
end; 
 
 
function tel_cut_1(ip:PChar;sock:integer):integer;//断开连接 
var 
  pcomm:PChar; 
begin 
  pcomm:=pchar('quit'); 
  if  new_do_command(sock,ip,pcomm) then Result:=1 else Result:=0; 
end; 
 
 
function saveconfig_0(ip:PChar;sock:integer):integer;  //保存配置 
var 
  pcommd:PChar; 
  result_buf:pchar; 
  buflen:integer; 
  ifsucc:Boolean; 
  str,cc:String; 
begin 
  buflen:=1024*16; 
  result_buf:=AllocMem(buflen*sizeof(char)); 
  pcommd:=pchar('write'); 
  new_do_command(sock,ip,pcommd); 
  while True do 
    begin 
      Sleep(100); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
        str:=str+string(result_buf) 
      else 
        Break; 
      cc:=RightStr(str,1); 
      if cc='#' then 
        Break; 
    end; 
  if Pos('[OK]',str)>0 then 
    Result:=1 
  else 
    Result:=0; 
    FreeMem(result_buf,1024*16); 
end; 
 
function run_command_get_0(ip, commd: pchar; sock: integer): TStringList; 
var 
  resu_strlist:TStringList; 
  result_buf:pchar; 
  buflen,i:integer; 
  str,s,ss,w,cc,str_1:String; 
  c:pchar; 
  ifsucc:Boolean; 
begin 
  if  new_do_command(sock,ip,commd) then 
  begin 
    buflen:=1024*16; 
    result_buf:=AllocMem(buflen*sizeof(char)); 
    while True do 
    begin 
      Sleep(100); 
      ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
      if ifsucc then 
        str:=str+string(result_buf) 
      else 
        Break; 
      w:=''; 
      w:=RightStr(str,10); 
      cc:=RightStr(str,1); 
      if (w=' --More-- ')or (cc='#') then 
        Break; 
    end; 
    s:=RightStr(str,10); 
    ss:=' --More-- '; 
    c:=' '; 
    while s=ss do 
      begin 
 
      if new_do_command(sock,ip,c) then 
         begin 
         str_1:=''; 
            while True do 
              begin 
                Sleep(100); 
                ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
                if ifsucc then 
                  str_1:=str_1+string(result_buf) 
                else 
                  Break; 
                w:=''; 
                w:=RightStr(str_1,10); 
                cc:=RightStr(str_1,1); 
                if (w=' --More-- ')or (cc='#') then 
                  Break; 
              end; 
         end; 
        str:=str+str_1; 
        s:=RightStr(str,10); 
      end; 
 
 
      resu_strlist:=page_open_0(str); 
 
 
    for i := 0 to resu_strlist.Count-1 do 
      if Copy(resu_strlist.Strings[i],1,10)=' --More-- ' then 
        resu_strlist.Strings[i]:=' '+Trim(MidStr(resu_strlist.Strings[i],11,length(resu_strlist.Strings[i]))); 
 
 
    FreeMem(result_buf,1024*16); 
    Result:=resu_strlist; 
  end; 
end; 
 
 
 
procedure get_ip_0(ip:PChar;sock:integer;var Ag:strecord); //取用户信息 
var 
  pcommd:PChar; 
  filee:TStringList; 
  i,j:Integer; 
  s,ss:String; 
  Fip:string; 
  ex:Boolean; 
begin 
  filee:=TStringList.Create; 
  pcommd:=pchar('show ip nat tran'); 
  filee:=run_command_get_0(ip,pcommd,sock); 
  for i := 0 to filee.Count-1 do 
  begin 
    ss:=trim(filee.Strings[i]); 
    ss:=trim(MidBStr(ss,pos(' ',ss)+1,length(ss))); 
    ss:=trim(MidBStr(ss,pos(' ',ss)+1,length(ss))); 
    fip:=trim(LeftBStr(ss,pos(':',ss)-1)); 
    if Fip='' then Continue; 
    ex:=False; 
    for j := 0 to Length(ag)-1 do 
    begin 
      if Ag[j].ip=Fip then 
      begin 
        Ag[j].count:=Ag[j].count+1; 
        ex:=True; 
        Break; 
      end; 
    end; 
    if not ex then 
    begin 
      SetLength(Ag,length(Ag)+1); 
      Ag[length(Ag)-1].ip:=Fip; 
      Ag[length(Ag)-1].count:=1; 
    end; 
  end; 
  filee.Destroy; 
end; 
 
 
 
function tel_cut_0(ip:PChar;sock:integer):integer;//断开连接 
var 
  pcomm:PChar; 
begin 
  pcomm:=pchar('exit'); 
  if  new_do_command(sock,ip,pcomm) then Result:=1 else Result:=0; 
end; 
 
function addroute_0(ip:PChar;sock:integer;id:integer;DestinaIP:String;DestinaMask:string;nexthop:String):integer;   //添加删除路由 
var 
  pcommd:PChar; 
  result_buf:pchar; 
  buflen:integer; 
  ifsucc:Boolean; 
  str,str1,s:String; 
begin 
  pcommd:=pchar('configure terminal'); 
  new_do_command(sock,ip,pcommd); 
  case id of 
    0:pcommd:=pchar('ip route '+DestinaIP+' '+DestinaMask+' '+nexthop); 
    1:pcommd:=pchar('no ip route '+DestinaIP+' '+DestinaMask+' '+nexthop); 
  end; 
  new_do_command(sock,ip,pcommd); 
  pcommd:=pchar('exit'); 
  new_do_command(sock,ip,pcommd); 
 
        buflen:=1024*16; 
        result_buf:=AllocMem(buflen*sizeof(char)); 
         while True do 
          begin 
            Sleep(100); 
             ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
            if ifsucc then 
                str:=str+string(result_buf) 
            else 
              Break; 
             s:= RightStr(str,2); 
             str1:=LeftStr(s,1); 
             s:=RightStr(s,1); 
            if (s='#')and(str1<>')') then 
             Break; 
          end; 
          FreeMem(result_buf,1024*16); 
  Result:=1; 
end; 
 
function addroute_1(ip:PChar;sock:integer;id:integer;DestinaIP:String;DestinaMask:string;nexthop:String):integer;   //添加删除路由 
var 
  pcommd:PChar; 
  result_buf:pchar; 
  buflen:integer; 
  str:String; 
  ifsucc:Boolean; 
begin 
  pcommd:=pchar('system-view'); 
  new_do_command(sock,ip,pcommd); 
  case id of 
    0:pcommd:=pchar('ip route-static '+DestinaIP+' '+DestinaMask+' '+nexthop); 
    1:pcommd:=pchar('undo ip route-static '+DestinaIP+' '+DestinaMask+' '+nexthop); 
  end; 
  new_do_command(sock,ip,pcommd); 
  pcommd:=pchar('quit'); 
  new_do_command(sock,ip,pcommd); 
 
          buflen:=1024*16; 
        result_buf:=AllocMem(buflen*sizeof(char)); 
        str:=''; 
         while True do 
          begin 
            Sleep(100); 
             ifsucc:=ReadResult(sock,ip,result_buf,buflen); 
            if ifsucc then 
                str:=str+string(result_buf) 
            else 
              Break; 
            if Pos('>',str)>0 then Break; 
          end; 
          FreeMem(result_buf,1024*16); 
 
  Result:=1; 
end; 
 
 
procedure TForm8.Button1Click(Sender: TObject); 
var 
  i,j,k:integer; 
  s,s1,s2,s3:String; 
  g:integer; 
begin 
  Fsock:=-1; 
  if ch=0 then 
    g:=tel_conn_0(pchar(Trim(Edit1.Text)),Fsock,pchar(':'),pchar(Trim(Edit2.Text)),pchar(Trim(Edit3.Text))); 
  if ch=1 then 
    g:=tel_conn_1(pchar(Trim(Edit1.Text)),Fsock,pchar(':'),pchar(Trim(Edit2.Text)),pchar(Trim(Edit3.Text))); 
  if g=1 then 
    ShowMessage('连接成功!') 
  else 
    ShowMessage('连接失败!'); 
end; 
 
function page_open_0(str:string):TStringList; 
var 
  s:string; 
  i:integer; 
  strlist:TStringList; 
 
begin 
  strlist:=TStringList.Create; 
  while (str[1]=#$D)or(str[1]=#$A)do Delete(str,1,1); 
  i:=length(str); 
  while (str[i]=#$D)or(str[i]=#$A)do 
  begin 
   Delete(str,i-1,i); 
   i:=length(str); 
  end; 
  s:=''; 
  while Pos(#$D#$A,str)<>0 do 
  begin 
    s:=LeftStr(str,pos(#$D#$A,str)-1); 
    strlist.Add(s); 
    str:=MidStr(str,pos(#$D#$A,str)+2,length(str)); 
  end; 
 
  strlist.Add(str); 
  Result:=strlist; 
end; 
 
 
procedure TForm8.RadioButton1Click(Sender: TObject); 
begin 
  ch:=0; 
end; 
 
procedure TForm8.RadioButton2Click(Sender: TObject); 
begin 
  ch:=1; 
end; 
 
procedure TForm8.Button2Click(Sender: TObject); 
var 
  g:strecord; 
  ffg:TSetThread; 
  i:Integer; 
begin 
  Panel1.Enabled:=False; 
  if Assigned(slist) then 
    slist.Clear 
  else 
    slist:=TStringList.Create; 
 
  if Assigned(slist1) then 
    slist1.Clear 
  else 
    slist1:=TStringList.Create; 
{  if ch=0 then 
    get_ip_0(pchar(trim(Edit1.Text)),Fsock,g); 
  if ch=1 then 
    get_ip_1(pchar(trim(Edit1.Text)),Fsock,g); 
  Arraydx(g); 
    for i := 0 to Length(g)-1 do 
  begin 
    if i=0 then Edit6.Text:=IntToStr(g[0].count); 
    if g[i].countIDOK then 
  begin 
     Exit; 
  end; 
  for i := 0 to  slist.Count-1 do 
  begin 
    if ch=0 then 
      g:=addroute_0(pchar(Trim(Edit1.Text)),Fsock,0,slist[i],'255.255.255.255','null 0'); 
    if ch=1 then 
      g:=addroute_1(pchar(Trim(Edit1.Text)),Fsock,0,slist[i],'255.255.255.255','null 0'); 
  end; 
  if g=1 then 
  begin 
    if not autex then 
      ShowMessage('断开成功!') 
    else 
      autex:=False; 
    tdlcsip(trim(slist.Text)); 
  end else 
    if not autex then 
      ShowMessage('断开失败!') 
    else 
      autex:=False; 
end; 
 
procedure TForm8.Button4Click(Sender: TObject); 
var 
  g,i:Integer; 
begin 
  if Assigned(slist) then 
    slist.Clear 
  else 
    slist:=TStringList.Create; 
try 
  slist.LoadFromFile(ExtractFilePath(Application.ExeName)+'cctdlsc.txt'); 
except 
 
end; 
  for i := 0 to  slist.Count-1 do 
  begin 
    if ch=0 then 
      g:=addroute_0(pchar(Trim(Edit1.Text)),Fsock,1,slist[i],'255.255.255.255','null 0'); 
    if ch=1 then 
      g:=addroute_1(pchar(Trim(Edit1.Text)),Fsock,1,slist[i],'255.255.255.255','null 0'); 
  end; 
  if g=1 then 
  begin 
    if not undoautex then 
      ShowMessage('恢复成功!') 
    else 
      undoautex:=False; 
    DeleteFile(ExtractFilePath(Application.ExeName)+'cctdlsc.txt'); 
  end else 
    if not undoautex then 
      ShowMessage('恢复失败!') 
    else 
      undoautex:=False; 
end; 
 
procedure tdlcsip(Aoper: String); 
var 
  F:Textfile; 
  sp:String; 
begin 
 sp:=ExtractFilePath(Application.ExeName)+'cctdlsc.txt'; 
 AssignFile(F,sp); 
 try 
    system.Append(F); 
  except 
    Rewrite(F); 
  end; 
  Writeln(F,Aoper); 
  closeFile(F); 
end; 
 
 
procedure TForm8.Button7Click(Sender: TObject); 
begin 
  if Assigned(slist) then 
    slist.Clear 
  else 
    slist:=TStringList.Create; 
  slist.Add(trim(Edit5.Text)); 
  ShowMessage('OK!'); 
end; 
 
{ TSetThread } 
 
constructor TSetThread.Create(FSuspend: Boolean; ip: string; sock,Ach: integer); 
begin 
  inherited Create(FSuspend); 
  FTip:=ip; 
  FTsock:=sock; 
  SetLength(FTg,0); 
  FTch:=Ach; 
end; 
 
procedure TSetThread.Execute; 
begin 
  FreeOnTerminate:=True; 
  OnTerminate:=MyTerminate; 
  if FTch=0 then 
    get_ip_0(pchar(FTip),FTsock,ftg); 
  if FTch=1 then 
    get_ip_1(pchar(FTip),FTsock,ftg); 
  Arraydx(ftg); 
 
end; 
 
procedure TSetThread.MyTerminate(Sender: Tobject); 
var 
  i:Integer; 
  Myip:String; 
begin 
  for i := 0 to Length(ftg)-1 do 
  begin 
  Myip:=Form8.IdIPWatch1.LocalIP; 
    if ftg[i].countMyip) then 
      slist.Add(ftg[i].ip); 
    slist1.Add(ftg[i].ip+'有'+inttostr(ftg[i].count)+'个连接'); 
  end; 
  if not autex then 
    ShowMessage(slist1.Text) 
  else 
    Form8.Button3.Click; 
  Form8.Panel1.Enabled:=True; 
 
end; 
 
procedure TForm8.CheckBox1Click(Sender: TObject); 
begin 
   Timer1.Enabled:= CheckBox1.Checked; 
   Timer2.Enabled:= CheckBox1.Checked; 
end; 
 
procedure TForm8.Timer1Timer(Sender: TObject); 
begin 
  Button2.Click; 
  autex:=True; 
end; 
 
procedure TForm8.Timer2Timer(Sender: TObject); 
begin 
  Button4.Click; 
  undoautex:=True; 
end; 
 
end.