Hola paquechu.
No respondí el mensaje
IP Dentro de una red por que no había entendido cuál era la finalidad de la función php, según entiendo ahora, es comprobar si una dirección IP pertenece a determinada Red.
Estuve leyendo un poco al respecto (
Direccion IP) e hice unas pruebas y hasta donde ví la funcion parece trabajar bién.
Código Delphi
[-]
function IsIPBelongsToNet(sIP, sRed: string): Boolean;
var
Mask, IP, Red: LongWord;
TS : TStrings;
i : Integer;
begin
Mask := $FFFFFFFF;
i := Pos('/', sIP);
if i <> 0 then
begin
Mask := $FFFFFFFF shl (32 - StrToInt(Copy(sIP, i+1, MaxInt)));
Delete(sIP, i, MaxInt);
end;
TS := TStringList.Create;
try
ExtractStrings([' ','.'], [], PChar(sIP), TS);
IP := StrToInt(TS[0]);
for i:= 1 to TS.Count-2 do
begin
IP := IP or StrToInt(TS[i]);
IP := IP shl 8;
end;
IP := IP or StrToInt(TS[TS.Count-1]);
TS.Clear;
ExtractStrings([' ','.'], [], PChar(sRed), TS);
Red := StrToInt(TS[0]);
for i:= 1 to TS.Count-2 do
begin
Red := Red or StrToInt(TS[i]);
Red := Red shl 8;
end;
Red := Red or StrToInt(TS[TS.Count-1]);
Result := (IP and Mask) = (Red and Mask);
finally
TS.Free
end
end;
Ejemplo de uso:
Código Delphi
[-]
procedure TForm1.Button1Click(Sender: TObject);
const
CLASE_A = '/8';
CLASE_B = '/16';
CLASE_C = '/24';
begin
if IsIPBelongsToNet('192.168.1.80'+CLASE_C, '192.168.2.0') then
ShowMessage('pertenece a la red')
else
ShowMessage('no pertenece a la red');
if IsIPBelongsToNet('10.100.40.30/11', '10.127.0.0' ) then
ShowMessage('pertenece a la red')
else
ShowMessage('no pertenece a la red');
end;
Espero que al menos te oriente por donde empezar...
Saludos.