Thema: IP Range

Einzelnen Beitrag anzeigen

xaromz

Registriert seit: 18. Mär 2005
1.682 Beiträge
 
Delphi 2006 Enterprise
 
#7

Re: IP Range

  Alt 20. Mär 2006, 00:38
Hallo,

wie wär's hiermit:
Delphi-Quellcode:
type
  TIPAddr = array[0..3] of Byte;

function GetNext(var IPAddr: TIPAddr): Boolean;
var
  C: Integer;
begin
  Result := True;
  for C := 3 downto 0 do
  begin
    if IPAddr[C] < 255 then
    begin
      Inc(IPAddr[C]);
      Exit;
    end;
    IPAddr[C] := 0;
  end;
  Result := False;
end;

function IsBelowOrEqual(IP, Limit: TIPAddr): Boolean;
begin
  Result := (IP[0] shl 24 + IP[1] shl 16 + IP[2] shl 8 + IP[3]) <=
    (Limit[0] shl 24 + Limit[1] shl 16 + Limit[2] shl 8 + Limit[3]);
end;
Anwendung:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  Start, Stop: TIPAddr;
begin
  Start[0] := 192;
  Start[1] := 168;
  Start[2] := 0;
  start[3] := 1;

  Stop[0] := 192;
  Stop[1] := 168;
  Stop[2] := 1;
  Stop[3] := 10;
  repeat
    ListBox1.Items.Add(IntToStr(Start[0]) + '.' + IntToStr(Start[1]) + '.' +
      IntToStr(Start[2]) + '.' + IntToStr(Start[3]));
    if not GetNext(Start) then
      Exit;
  until not IsBelowOrEqual(Start, Stop);
end;
Gruß
xaromz
  Mit Zitat antworten Zitat