(01-09-2018, Saat: 09:12)ssahinoglu Adlı Kullanıcıdan Alıntı: İki adresi 4'er sayıya ayırıp iç içe 4 adet for döngüsü yapman lazım.
Fakat büyüklük sırası karışır ve kümenin tamamını kapsayamaz.
Bu yüzden en güzeli ip adresini 255 tabanında integer sayıya çevirip tekli for kullan.
Her aşamada integeri 1 artırıp tekrar ip'ye çevir.
function Ip2Int(i1,i2,i3,i4:byte):integer;
begin
result := (i1 shl 24) + (i2 shl 16) + (i3 shl 8) + (i4);
end;
function Int2Ip(ip:integer):string;
var
dizi:array[1..4] of byte absolute ip;
begin
result := dizi[4].ToString + '.' + dizi[3].ToString + '.' + dizi[2].ToString + '.' + dizi[1].ToString;
end;
Başardım. Gayet güzel Çalışıyor. Dediğiniz gibi Tek Döngü ile hallettim.
type
IPv4 = record
Octet: array [1..4] of Byte ;
end;
const
LISTESIRA = 0;
LISTEIP = 1;
LISTEMAC = 2;
LISTEPROTOKOL = 3;
LISTEPORT = 4;
OKTET1 = 1;
OKTET2 = 2;
OKTET3 = 3;
OKTET4 = 4;
var
BaslangicIP : IPv4;
BitisIP : IPv4;
function Ip2Int(i1,i2,i3,i4:byte):integer;
begin
result := (i1 shl 24) + (i2 shl 16) + (i3 shl 8) + (i4);
end;
function Int2Ip(ip:integer):string;
var
dizi:array[1..4] of byte absolute ip;
begin
if ((Dizi[4] = 0) or (Dizi[4] = 255) or
(Dizi[3] = 0) or (Dizi[3] = 255) or
(Dizi[2] = 0) or (Dizi[2] = 255) or
(Dizi[1] = 0) or (Dizi[1] = 255)) then
begin
result := '' ;
end
else
begin
result := dizi[4].ToString + '.' +
dizi[3].ToString + '.' +
dizi[2].ToString + '.' +
dizi[1].ToString;
end;
end;
procedure ListeEkle(var Liste:TStringGrid;pip,pmac,pprotokol,pport:string);
var
eklenensatir : integer;
begin
Liste.RowCount := Liste.RowCount + 1;
eklenensatir := Liste.RowCount-1;
Liste.Cells[LISTESIRA,eklenensatir] := inttostr(eklenensatir);
Liste.Cells[LISTEIP,eklenensatir] := trim(pip);
Liste.Cells[LISTEMAC,eklenensatir] := trim(pmac);
Liste.Cells[LISTEPROTOKOL,eklenensatir] := trim(pprotokol);
Liste.Cells[LISTEPORT,eklenensatir] := trim(pport);
Liste.Row := eklenensatir;
end;
procedure IPListOlustur(var Baslama,bitis:IPv4;var Liste:TStringGrid);
var
IPilk : integer;
IPSon : integer;
sira : integer;
IPADDR : String;
begin
IPilk := Ip2Int(Baslama.Octet[Oktet1],Baslama.Octet[Oktet2],
Baslama.Octet[Oktet3],Baslama.Octet[Oktet4]);
IPSon := Ip2Int(Bitis.Octet[Oktet1],Bitis.Octet[Oktet2],
Bitis.Octet[Oktet3],Bitis.Octet[Oktet4]);
for sira := IPilk to IPSon do
begin
IPADDR := Int2Ip(sira);
if (IPADDR <> '') then
ListeEkle(Liste,IPADDR,'','','');
Application.ProcessMessages;
end;
end;
IPListOlustur(BaslangicIP,BitisIP,IPList);