192.168.0.1
...
192.168.0.255
192.168.1.1
...
192.168.1.255从IP地址192.168.0.1到192.168.1.255之间的IP地址要怎么生成哪位能提供一个这样的算法

解决方案 »

  1.   

    生成?两个FOR循环就OK啦
    var
     IPList:TStringList;IPList:=TStringList.Create;for i:=0 to 1 do
      for j:= 1 to 255 do
        IPList.Line.Add(format('192.168.%d.%d',[i,j]));是这个意思吗?
      

  2.   

    procedure IPR(A1,A2,A3,A4,B1,B2,B3,B4:integer);
    begin
       If (A4 < B4) Or (A3 < B3) Or (A2 < B2) Or (A1 < B1) Then
       begin
          inc(A4);
          if A4>255 then
          begin
             A4:=1;inc(A3);
             if A3>255 then
             begin
                A3:=1;inc(A2);
                if A2>255 then
                begin
                   A2:=1;
                   inc(A1);
                end;
             end;
          end;
          IPR(A1, A2, A3, A4, B1, B2, B3, B4);
       end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      IPR(192,168,1,1,192,168,10,1);//这样可以
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      IPR(192,168,1,1,192,169,1,1);//这样溢出了,还有什么算法?
    end;
      

  3.   

    procedure IPR(A1,A2,A3,A4,B1,B2,B3,B4:integer);//用循环就不会溢出
    begin
       repeat
          form1.ListBox1.Items.Add(format('%d.%d.%d.%d',[A1,A2,A3,A4]));
          if form1.ListBox1.Items.Count>3000 then       form1.ListBox1.Items.Clear ;      inc(A4);
          if A4>255 then
          begin
             A4:=1;inc(A3);
             if A3>255 then
             begin
                A3:=1;inc(A2);
                if A2>255 then
                begin
                   A2:=1;
                   inc(A1);
                end;
             end;
          end;
          Application.ProcessMessages ;
         // IPR(A1, A2, A3, A4, B1, B2, B3, B4);
       until not((A4 < B4) Or (A3 < B3) Or (A2 < B2) Or (A1 < B1));
    end;