uses Winsock
function CompareIps(IP1, IP2: string): string;
var
a, b: TInAddr;
begin
a.S_addr := inet_addr(PChar(IP1));
b.S_Addr := inet_addr(PChar(IP2));
if ntohl(a.S_addr) > ntohl(b.S_addr) then
Result := IP1
else if ntohl(b.S_addr) > ntohl(a.S_addr) then
Result := IP2
else
Result := 'EQUAL';
end;
function IPSort(List: TStringList; Index1, Index2: Integer): Integer;
var
a, b: TInAddr;
begin
a.S_addr := inet_addr(PChar(List[Index1]));;
b.S_Addr := inet_addr(PChar(List[Index2]));;
if ntohl(a.S_addr) > ntohl(b.S_addr) then
Result := -1
else if ntohl(b.S_addr) > ntohl(a.S_addr) then
Result := 1
else
Result := 0;
end;
Sort IP :
rocedure TForm1.Button1Click(Sender: TObject);
var
IPList: TStringList;
begin
IPList := TStringList.Create;
try
IPList.Assign(Memo1.Lines);
IPList.CustomSort(IPSort);
Memo1.Lines.Assign(IPList);
finally
IPList.Free;
end;
end;
Compare IP :
procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption := CompareIPs('224.123.161.5', '224.123.161.5');
end;
Keine Kommentare:
Kommentar veröffentlichen