Author Topic: Identify network devices  (Read 1535 times)

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Identify network devices
« on: August 01, 2026, 01:35:07 pm »
I need a simple web server that also can output JSON answers. I also need a login system that can memorize connected before devices.

The question is how to organize the login system. What should I store on server-side to identify connected devices properly?

Maybe someone has a ready template for such server. That would be very nice if you share it.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 19626
  • Glad to be alive.
Re: Identify network devices
« Reply #1 on: August 01, 2026, 01:39:20 pm »
You store a hash, not the credentials.
This has been answered umpty times.
You can *and should* avoid session cookies by simply storing IP and browser string. That is the correct way.

If you need cookies...... especially the "legitimate interest" ones..... you are on a wrong path.
That will be gone within months.(Finally)
« Last Edit: August 01, 2026, 01:53:34 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #2 on: August 01, 2026, 04:50:01 pm »
Quote
storing IP and browser string
Could you show how to get that in code?

IP can be in two versions v4 and v6. Which one will be returned?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LeP

  • Guest
Re: Identify network devices
« Reply #3 on: August 02, 2026, 09:55:07 am »
You should have something in FPC web ecosystem that get "USER-AGENT" and "REMOTEIP" from http header (that are strings).

So, maintain Hash of those is not a problem (you don't need to know if it's IPv6 or IPv4).

Be carefull that "USER-AGENT" contains very common datas and REMOTEIP doesn't securely identify a machine.

So this can be used in a local network where IP adress are normally assigned statically or with long lease, and for a short time.

The use of MAC ADDRESS is a better choice instead of IP in a local lan.

dbannon

  • Hero Member
  • *****
  • Posts: 3882
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Identify network devices
« Reply #4 on: August 02, 2026, 10:52:41 am »
If you are using the (really good) fpc http client and server, this will help -

Firstly, you need to override the function that gets called when a request is made, eg -

Code: Pascal  [Select][+][-]
  1. TMistyHTTPServer = Class(TFPHTTPServer)  
  2.     ...
  3.     procedure HandleRequest(Var ARequest: TFPHTTPConnectionRequest;
  4.                             Var AResponse : TFPHTTPConnectionResponse); override;

Then implement that function
Code: Pascal  [Select][+][-]
  1. procedure TMistyHTTPServer.HandleRequest(var ARequest: TFPHTTPConnectionRequest;
  2.                                         var AResponse: TFPHTTPConnectionResponse);
  3. ...
  4.     IP := ARequest.RemoteAddress;

Both ARequest and AResponse have lots of info in there, sadly not documented but look in the source ....

Remember IP addresses are reassignable, one machine may have a particular IP today but sure does not mean its the same tomorrow.

Are you connecting as a web service where you have control of the client ?  Better to send a unique code rather than relying on IP.

Davo



Lazarus 4, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #5 on: August 02, 2026, 03:38:14 pm »
Where I can download OpenSSL libraries needed for work of SSL?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #6 on: August 02, 2026, 05:13:56 pm »
I found https://kb.firedaemon.com/support/solutions/articles/4000121705
This version OpenSSL 3.0.21 LTS ZIP x86+x64 works.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #7 on: August 02, 2026, 05:23:58 pm »
I built a simple application to test that it is working.
The code:
Code: Pascal  [Select][+][-]
  1. program SimpleHTTPServer;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   Classes, fphttpserver, opensslsockets
  10.   { you can add units after this };
  11.  
  12. {$R *.res}
  13.  
  14. type
  15.  
  16.   { TTempObj }
  17.  
  18.   TTempObj = object
  19.   public
  20.     procedure ProceedRequest(Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);
  21.   end;
  22.  
  23. { TTempObj }
  24.  
  25. procedure TTempObj.ProceedRequest(Sender: TObject;
  26.   var ARequest: TFPHTTPConnectionRequest;
  27.   var AResponse: TFPHTTPConnectionResponse);
  28. begin
  29.   WriteLn('1');
  30.   AResponse.Content:= ARequest.QueryString + 'Test';
  31.   AResponse.Code:= 200;
  32. end;
  33.  
  34. var
  35.   TempObj: TTempObj;
  36.   Server: TFPHttpServer;
  37. begin
  38.   Server:= TFPHttpServer.Create(nil);
  39.   Server.UseSSL:= True;
  40.   Server.Port:= 443;
  41.   Server.OnRequest:= @TempObj.ProceedRequest;
  42.   Server.ThreadMode:= tmThread;
  43.   Server.Active:= True;
  44.   Server.Free;
  45. end.
  46.  
When I run it and trying access http://localhost:443/here I getting ERR_CONNECTION_RESET and nothing input into console. What is wrong?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LeP

  • Guest
Re: Identify network devices
« Reply #8 on: August 02, 2026, 05:29:10 pm »
You must use a certificate for your server to use SSL.

Create one with OpenSSL if you server is  local or with Let's Encrypt is the server is public.

Next time, if you want to download OpenSSL runtime, you can download here (a lot of version availbale for all platforms): https://github.com/TaurusTLS-Developers/OpenSSL-Distribution/releases

« Last Edit: August 02, 2026, 05:32:49 pm by LeP »

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #9 on: August 02, 2026, 05:48:09 pm »
https://wiki.freepascal.org/fphttpserver This page says
Quote
If you do not set the certificate details, the HTTP server component will generate a temporary certificate, which may lead to a warning being displayed in the browser.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #10 on: August 02, 2026, 06:01:27 pm »
I figure out. I have to use this url https://localhost/here . Now it works.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #11 on: August 02, 2026, 06:07:23 pm »
How can I get route from Request?
I mean for https://localhost/here it should be /here.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LeP

  • Guest
Re: Identify network devices
« Reply #12 on: August 02, 2026, 06:26:43 pm »
I cannot help you more than this 'cause I don't know nothing about FPC web.

Attached: cert files (Crt and Private key) with config and command line instructions to create new one every time you need it.

Bye

LemonParty

  • Hero Member
  • *****
  • Posts: 619
Re: Identify network devices
« Reply #13 on: August 02, 2026, 09:02:03 pm »
Thank you, LeP.
I figure out how to get route. It is ARequest.URL property.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LeP

  • Guest
Re: Identify network devices
« Reply #14 on: August 02, 2026, 09:36:51 pm »
Thank you, LeP.
I figure out how to get route. It is ARequest.URL property.
I know, I use Indy and it exposed all things.

This is a sample (there is also FRemoteIP not visible in the screenshot).

URL is a pproperty that contain the full domain name (i.e.: www.google.com').
DOCUMENT is a property the contain the rest of the "line" (i.e.: /Index.html).
« Last Edit: August 02, 2026, 09:52:22 pm by LeP »

 

TinyPortal © 2005-2018