Ver Mensaje Individual
  #6  
Antiguo 27-04-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
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 [-]
// Devuelve True si pertenece o False de lo contrario
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
    // dirección IP
    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]);

    // Red
    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
  // direccionamiento con clase
  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');

  // direccionamiento sin clase
  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.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita