Change notification lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- P.curtis · 2020-04-15 19:12 Hi all, How can I get notified of network changes, ip address .... ? I use Win 10, I thought maybe there is a message or similar. ---------------------------------------------------------------------- Aidex · 2020-04-15 19:59 Unfortunately I do not have a Pascal code at hand, but this is probably the right Windows function for it. https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf- iphlpapi-notifyaddrchange ---------------------------------------------------------------------- Aidex · 2020-04-15 20:09 PS: But if you mean the public Internet address of your Internet router: it cannot be determined internally, but only by a query to an external server. Therefore there is no OS event for this. Search the forum for "Detect IP address" or similar. ---------------------------------------------------------------------- winni · 2020-04-15 23:55 Hi! Of course you can ask your router what  the public IP address is - BUT there is no way for all routers. Every router does it's own interface. With FritzBox you have to do a http get to typically 192.168.178.1. You get the first page and then filter out a string starting with "IP-Adresse" - as long as the languge is german. You see - even with one model you got already the language trouble. You can solve this with regex. But there are a lot of other routers out in the wild. Winni ---------------------------------------------------------------------- trev · 2020-04-16 05:17 Quote from: winni on April 16, 2020, 01:55:27 amthere is no way for all routers. Every router does it's own interface. Some routers (eg Siemens Speedstream 4x00, D-Link DSL-50x, Billion 741GE and 7300x) respond to SNMP requests (I used Synapse for this in the past). ---------------------------------------------------------------------- P.curtis · 2020-04-16 09:01 Quote from: winni on April 16, 2020, 01:55:27 amHi! Of course you can ask your router what  the public IP address is - BUT there is no way for all routers. Every router does it's own interface. With FritzBox you have to do a http get to typically 192.168.178.1. You get the first page and then filter out a string starting with "IP-Adresse" - as long as the languge is german. You see - even with one model you got already the language trouble. You can solve this with regex. But there are a lot of other routers out in the wild. Winni I managed find this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type   { TForm1 }   TForm1 = class (TForm)    Timer1: TTimer;    procedure FormCreate (Sender: TObject);    procedure Timer1Timer (Sender: TObject);    procedure FormDestroy (Sender: TObject);  private    AddrChangeEventHandle: THandle;    procedure CreateNotifyEvent;  public    {public declarations}   end ; var  Form1: TForm; implementation {$R *.lfm} function NotifyAddrChange ( out Handle : THANDLE; const Overlapped: OVERLAPPED): DWORD; stdcall ; external 'Iphlpapi.dll '; procedure TForm1.FormCreate (Sender: TObject);begin  AddrChangeEventHandle := CreateEvent(nil , false, false, nil);  CreateNotifyEvent;end; procedure TForm1.CreateNotifyEvent;var  N: THandle;  O: OVERLAPPED;  R: DWORD;begin  O.hEvent := AddrChangeEventHandle;   R := NotifyAddrChange (N, O);   if not ((R = NO_ERROR) or (R = ERROR_IO_PENDING)) then  begin    RaiseLastOSError;  end;end; procedure TForm1.FormDestroy (Sender: TObject);begin  CloseHandle (AddrChangeEventHandle);end; procedure TForm1.Timer1Timer(Sender: TObject);begin  if (WaitForSingleObject (AddrChangeEventHandle, 0) = WAIT_OBJECT_0) then  begin    ShowMessage ('IP was changed.');    CreateNotifyEvent;  end;end; end. Which is pointing me in the right direction ---------------------------------------------------------------------- Remy Lebeau · 2020-04-16 18:19 Quote from: Aidex on April 15, 2020, 10:09:59 pmBut if you mean the public Internet address of your Internet router: it cannot be determined internally, but only by a query to an external server. Not true.  If the router supports uPNP, its public WAN IP can be queried directly.   And as other replies states, there may be other query protocols supported, such as SNMP. Also note that if you are connected to an ISP that runs its customers behind a NAT on the ISP side, then querying an external server will report the ISPs public IP, not your router's IP. Quote from: Aidex on April 15, 2020, 10:09:59 pmTherefore there is no OS event for this. Actually, there is, at least on Windows, if uPNP is enabled: INATEventManager::put_ExternalIPAddressCallback() QuoteThe put_ExternalIPAddressCallback method enables the NAT application with UPnP technology to register a callback interface with the NAT. The system calls the first method in this callback interface if the external IP address of the NAT changes. INATExternalIPAddressCallback::NewExternalIPAddress QuoteThe system calls the NewExternalIPAddress method if the external IP address of the NAT computer changes.