Jump to content

Recommended Posts

Posted

Hi,

 

Actualy, i use the property "UniApplication.RemoteAddress" to get the remote IP of the user.

I would like to get this information before, when an exception broke the connexion "InvalidSession" or "TermnateSession" on the ServerModule.

The goal is to "auto connect" the user if his IP is in my list of "Admin IP".

 

Is it possible ?

Thanks

  • 1 month later...
Posted (edited)

Simple:   unisession.RemoteIP

It's embeded in the session. Otherwise, the server would not "howto knows"  where to send the data.

Edited by fredmontier
  • 1 year later...
Posted

Hi,

I am currently using UniSession.RemoteIP to obtain the ip of the sessions of the users that enter my application, however there is a firewall in the middle and UniSession.RemoteIP is registering the ip of the firewall and not of the sessions of each user.

Is there any way to get it ip from each user's session?

  • 4 years later...
Posted

i use this approach :

 

unit ServerModule;

.......

interface

.......

type
  TServerExternalData = record
   ExternalIP      : String; {77.137.79.118}
   City            : String; {Tel Aviv}
   Region          : String; {Tel Aviv}
   Country         : String; {IL}
   Location        : String; {32.0809,34.7806}
   InternetCompany : String; {AS12849 Hot-Net internet services Ltd}
   TimeZone        : String; {Asia\/Jerusalem}
  end;

 

on the PUBLIC section

.....

  public
    { Public declarations }
    function  GetExternalData() : TServerExternalData;
  end;

.....

implementation
{$R *.DFM}
.......

function TUniServerModule.GetExternalData() : TServerExternalData;
var
  LJsonObj : TJSONObject;
  Http     : TIdHttp;
  RsltStr  : String;
begin
  Result.ExternalIP      := '';
  Result.City            := '';
  Result.Region          := '';
  Result.Country         := '';
  Result.Location        := '';
  Result.InternetCompany := '';
  Result.TimeZone        := '';

  Try
    Http := TIdHTTP.Create(nil);
    try
      RsltStr := Http.Get('http://ipinfo.io/json');
      LJsonObj := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(RsltStr),0) as TJSONObject;
      // "ip":"77.137.79.118"
      // "city":"Tel Aviv",
      // "region":"Tel Aviv",
      // "country":"IL",
      // "loc":"32.0809,34.7806",
      // "org":"AS12849 Hot-Net internet services Ltd."
      // "timezone":"Asia\/Jerusalem"

      Result.ExternalIP      := LJsonObj.Get('ip').JsonValue.Value;
      Result.City            := LJsonObj.Get('city').JsonValue.Value;
      Result.Region          := LJsonObj.Get('region').JsonValue.Value;
      Result.Country         := LJsonObj.Get('country').JsonValue.Value;
      Result.Location        := LJsonObj.Get('loc').JsonValue.Value;
      Result.InternetCompany := LJsonObj.Get('org').JsonValue.Value;
      Result.TimeZone        := LJsonObj.Get('timezone').JsonValue.Value;
    Except;
    end;
  Finally
    FreeAndNil(LJsonObj);
    FreeAndNil(Http);
  End;
 

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...