uses StrUtils;
function IsIPInRange(IP2Check:
string; IPStart:
string; IPEnd:
string): Boolean;
type
TIPv4 =
record
Num1, Num2, Num3, Num4: Byte;
end;
var
IP2CheckSplitted, IPStartSplitted, IPEndSplitted: TIPv4;
function SplitIP(
IP:
string): TIPv4;
var
Pos1, Pos2: Integer;
begin
Pos1 := Pos('
.',
IP);
Result.Num1 := StrToInt(Copy(
IP, 1, Pos1 - 1));
Pos2 := PosEx('
.',
IP, Pos1 + 1);
Result.Num2 := StrToInt(Copy(
IP, Pos1 + 1, Pos2 - Pos1 - 1));
Pos1 := Pos2;
Pos2 := PosEx('
.',
IP, Pos1 + 1);
Result.Num3 := StrToInt(Copy(
IP, Pos1 + 1, Pos2 - Pos1 - 1));
Pos1 := Pos2;
Result.Num4 := StrToInt(Copy(
IP, Pos1 + 1, Length(
IP) - Pos1));
end;
begin
IP2CheckSplitted := SplitIP(IP2Check);
IPStartSplitted := SplitIP(IPStart);
IPEndSplitted := SplitIP(IPEnd);
Result :=
(IP2CheckSplitted.Num1 >= IPStartSplitted.Num1)
and (IP2CheckSplitted.Num1 <= IPEndSplitted.Num1)
and
(IP2CheckSplitted.Num2 >= IPStartSplitted.Num2)
and (IP2CheckSplitted.Num2 <= IPEndSplitted.Num2)
and
(IP2CheckSplitted.Num3 >= IPStartSplitted.Num3)
and (IP2CheckSplitted.Num3 <= IPEndSplitted.Num3)
and
(IP2CheckSplitted.Num4 >= IPStartSplitted.Num4)
and (IP2CheckSplitted.Num4 <= IPEndSplitted.Num4);
end;