* * *

Author Topic: Client IP Address  (Read 1305 times)

nugax

  • Jr. Member
  • **
  • Posts: 82
Client IP Address
« on: March 04, 2018, 11:01:52 pm »
How can I simply get a client ip and/or dns hostname
-Nugax

BlueIcaro

  • Hero Member
  • *****
  • Posts: 561
Re: Client IP Address
« Reply #1 on: March 04, 2018, 11:10:07 pm »
Hi, I used  Indy components. With  TidIPWatch component you can write
Code: [Select]
MiIp := IdIPWatch1.CurrentIP;

/BlueIcaro
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

nugax

  • Jr. Member
  • **
  • Posts: 82
Re: Client IP Address
« Reply #2 on: March 05, 2018, 03:16:04 pm »
Indy components? I am not familiar. Can you elaborate on how/where I can use these?
-Nugax

Leledumbo

  • Hero Member
  • *****
  • Posts: 7908
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Client IP Address
« Reply #3 on: March 06, 2018, 10:58:23 am »
What do you use at server side? Plain socket? Some library?

BlueIcaro

  • Hero Member
  • *****
  • Posts: 561
Re: Client IP Address
« Reply #4 on: March 08, 2018, 07:48:46 am »
Indy components? I am not familiar. Can you elaborate on how/where I can use these?
Install the package. Use it.
Like any other  component in Lazarus
http://wiki.freepascal.org/Indy_with_Lazarus#How_to_install
/BlueIcaro
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 408
    • Lebeau Software
Re: Client IP Address
« Reply #5 on: March 12, 2018, 10:48:44 pm »
Install the package. Use it.
Like any other  component in Lazarus
http://wiki.freepascal.org/Indy_with_Lazarus#How_to_install

Note that Indy is in Lazarus' OPM, so you don't need to install it manually per those instructions anymore.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

tudi_x

  • Sr. Member
  • ****
  • Posts: 457
Re: Client IP Address
« Reply #6 on: March 13, 2018, 10:14:27 am »
IP without Indy:

Code: Pascal  [Select]
  1. uses Process
  2.  
  3. function GetIpAddrList(): string;
  4. var
  5.   AProcess: TProcess;
  6.   s: string;
  7.   sl: TStringList;
  8.   i, n: integer;
  9.  
  10. begin
  11.   Result:='';
  12.   sl:=TStringList.Create();
  13.   {$IFDEF WINDOWS}
  14.   AProcess:=TProcess.Create(nil);
  15.   AProcess.CommandLine := 'ipconfig.exe';
  16.   AProcess.Options := AProcess.Options + [poUsePipes, poNoConsole];
  17.   try
  18.     AProcess.Execute();
  19.     Sleep(500); // poWaitOnExit not working as expected
  20.     sl.LoadFromStream(AProcess.Output);
  21.   finally
  22.     AProcess.Free();
  23.   end;
  24.   for i:=0 to sl.Count-1 do
  25.   begin
  26.     if (Pos('IPv4', sl[i])=0) and (Pos('IP-', sl[i])=0) and (Pos('IP Address', sl[i])=0) then Continue;
  27.     s:=sl[i];
  28.     s:=Trim(Copy(s, Pos(':', s)+1, 999));
  29.     if Pos(':', s)>0 then Continue; // IPv6
  30.     Result:=Result+s+'  ';
  31.   end;
  32.   {$ENDIF}
  33.   {$IFDEF UNIX}
  34.   AProcess:=TProcess.Create(nil);
  35.   AProcess.CommandLine := '/sbin/ifconfig';
  36.   AProcess.Options := AProcess.Options + [poUsePipes, poWaitOnExit];
  37.   try
  38.     AProcess.Execute();
  39.     //Sleep(500); // poWaitOnExit not working as expected
  40.     sl.LoadFromStream(AProcess.Output);
  41.   finally
  42.     AProcess.Free();
  43.   end;
  44.  
  45.   for i:=0 to sl.Count-1 do
  46.   begin
  47.     n:=Pos('inet addr:', sl[i]);
  48.     if n=0 then Continue;
  49.     s:=sl[i];
  50.     s:=Copy(s, n+Length('inet addr:'), 999);
  51.     Result:=Result+Trim(Copy(s, 1, Pos(' ', s)))+'  ';
  52.   end;
  53.   {$ENDIF}
  54.   sl.Free();
  55. end;

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus