Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WebApplication.IP change from IW15.x to IW16.2
#1
I have a dll which in Audit records user activity and IP, using WebApplication.IP. This under delphi 10.2.3 and IW15.x

A new application using same audit (Delphi 12.2 IW16.2), reports under WebApplication.IP our internal server rather than user IP.

Should I use a diferent routine?
Reply
#2
(09-09-2026, 03:02 AM)alex.trejo@tttnet.com.mx Wrote: I have a dll which in Audit records user activity and IP, using WebApplication.IP. This under delphi 10.2.3 and IW15.x

A new application using same audit (Delphi 12.2 IW16.2), reports under WebApplication.IP our internal server rather than user IP.

Should I use a diferent routine?

This is what I use to get the actual IP:

String rip = WebApplication->Request->GetRawHeaderValue("X-Real-IP");
if(rip == "") rip = WebApplication->IP;
Reply
#3
Since we have an internal proxy, we obtained it this way:

function TIWUserSession.DameHeaderHTTP(const ANombre: string): string;
var
  i, p: Integer;
  Linea: string;
begin
  Result:='';
  for i:=0 to WebApplication.Request.RawHeaders.Count-1 do
  begin
    Linea:=WebApplication.Request.RawHeaders[i];
    p:=Pos(':',Linea);
    if (p>0) and SameText(Trim(Copy(Linea,1,p-1)),ANombre) then
    begin
      Result:=Trim(Copy(Linea,p+1,MaxInt));
      Exit;
    end;
  end;
end;

function TIWUserSession.DameIPCliente: string;
var
  IPRemota, XFF: string;
  p: Integer;
begin
  IPRemota:=WebApplication.Request.RemoteAddr;
  Result:=IPRemota;

  if IPRemota='XXX.XXX.XXX.XXX' then  //internal proxy IP
  begin
    XFF:=DameHeaderHTTP('X-Forwarded-For');

    // Si hubiera varios valores, toma el último agregado por el proxy.
    p:=LastDelimiter(',',XFF);
    if p>0 then
      XFF:=Trim(Copy(XFF,p+1,MaxInt))
    else
      XFF:=Trim(XFF);

    if XFF<>'' then
      Result:=XFF;
  end;
end;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)