Come conoscere il proprio indirizzo IP pubblico – Support Elsist https://support.elsist.biz/forums/topic/come-conoscere-il-proprio-indirizzo-ip-pubblico/feed/ Fri, 30 Oct 2026 08:52:49 +0000 https://bbpress.org/?v=2.6.20 it-IT https://support.elsist.biz/forums/topic/come-conoscere-il-proprio-indirizzo-ip-pubblico/#post-70973 Come conoscere il proprio indirizzo IP pubblico https://support.elsist.biz/forums/topic/come-conoscere-il-proprio-indirizzo-ip-pubblico/#post-70973 Fri, 17 Mar 2023 15:47:13 +0000 Anonimo Stò utilizzando dei servizi di Dynamic DNS gestiti dal router ma non sempre l’aggiornamento dell’indirizzo IP avviene in tempi rapidi.

Volevo sapere se c’è la possibilità da programma PLC SlimLine di conoscere l’indirizzo IP pubblico del router a cui è connesso (nel caso specifico un WLINK WL-R100x).

]]>
https://support.elsist.biz/forums/topic/come-conoscere-il-proprio-indirizzo-ip-pubblico/#post-70975 Rispondi a: Come conoscere il proprio indirizzo IP pubblico https://support.elsist.biz/forums/topic/come-conoscere-il-proprio-indirizzo-ip-pubblico/#post-70975 Fri, 17 Mar 2023 15:49:46 +0000 Sergio Bertana Se hai la necessità di conoscere l’indirizzo IP pubblico con il quale il tuo sistema SlimLine esce su Internet hai due possibilità.

Tutti i router supportano la registrazione presso servizi di Dynamic DNS, quindi puoi registrarti e poi eseguendo il FB DNSRequest effettuare la richiesta di risoluzione URL.

Ma se non vuoi appoggiarti a servizi di DNS dinamico puoi connetterti a siti che offrono gratuitamente il servizio di segnalazione indirizzo IP, ad esempio ipify.org. Inviando una richiesta API al sito ti verrà inviato in risposta una stringa con il tuo indirizzo IP pubblico, ecco il listato del programma HTTPIPIfy che esegue la richiesta. Attivando da debug la variabile Request nel buffer Page ti verrà ritornato il tuo indirizzo IP pubblico.

PROGRAM HTTPIPIfy
VAR
    i : UDINT; (* Auxiliary variable *)
    Request : BOOL; (* Request command *)
    FlipFlop : BOOL; (* Program Flip/Flop *)
    Errors : UDINT; (* Execution errors *)
    Page : STRING[ 64 ]; (* Page buffer *)
    TCPClient : SysTCPClient; (* TCP client management *)
    HTTPRq : HTTPClient_v4; (* HTTP client *)
END_VAR

// *****************************************************************************
// PROGRAM "HTTPIPIfy"
// *****************************************************************************
// The program send an API request to "api.ipify.org" and receive back the own
// public IP address.
// -----------------------------------------------------------------------------

    // -------------------------------------------------------------------------
    // INITIALIZATIONS
    // -------------------------------------------------------------------------
    // Program initializations.

    IF (SysFirstLoop) THEN

        // Set TCPClient parameters.

        TCPClient.PeerAdd:=ADR('api.ipify.org'); //Peer address
        TCPClient.PeerPort:=80; //Peer port
        TCPClient.LocalAdd:=ADR('0.0.0.0'); //Local address
        TCPClient.LocalPort:=0; //Local port
        TCPClient.FlushTm:=50; //Flush time (mS)
        TCPClient.LifeTm:=20; //Life time (S)
        TCPClient.RxSize:=512; //Rx buffer size
        TCPClient.TxSize:=512; //Tx buffer size

        // Set HTTPClient parameters.

        HTTPRq.RMethod:=0; //Request method, GET
        HTTPRq.SpyOn:=TRUE; //Activate the spy
        HTTPRq.HostName:=TCPClient.PeerAdd; // Hostname
        HTTPRq.Page:=ADR(''); //Web page
        HTTPRq.Request:=eNULL; //Request string
        HTTPRq.Header:=eNULL; //HTTP header
        HTTPRq.DBSize:=512; //Data buffer size
        HTTPRq.Timeout:=10.0; //Execution timeout
    END_IF;

    // -------------------------------------------------------------------------
    // MANAGE CONNECTION
    // -------------------------------------------------------------------------
    // Manage the connection.

    TCPClient(Connect:=HTTPRq.Connect); //TCPClient management
    HTTPRq(File:=TCPClient.File); //HTTP client
    IF (HTTPRq.Fault) THEN Errors:=Errors+1; FlipFlop:=FALSE; END_IF;

    // -------------------------------------------------------------------------
    // PROGRAM SEQUENCIES
    // -------------------------------------------------------------------------
    // Program sequencies.

    IF NOT(FlipFlop) THEN

        // ---------------------------------------------------------------------
        // Wait for request command.

        HTTPRq.Enable:=FALSE; //HTTP enable
        HTTPRq.Send:=FALSE; //Send request
        IF NOT(Request) THEN RETURN; END_IF;
        Request:=FALSE; //Request command
        
        // Initialize buffers and enable client.

        i:=Sysmemset(ADR(Page), 0, SIZEOF(Page)); //Empty page buffer
        HTTPRq.Enable:=TRUE; //HTTP enable
        HTTPRq.Send:=TRUE; //Send request
        FlipFlop:=TRUE; //Program Flip/Flop
    ELSE

        // ---------------------------------------------------------------------
        // Page data are received from server by chunked. When a chunk has been
        // received DBChars returns its length. The API service sends back your
        // public IP address on a text string like: "xxx.xxx.xxx.xxx".

        IF ((HTTPRq.DBChars <> 0) AND (HTTPRq.HPSelector)) THEN
            IF ((Sysstrlen(ADR(Page))+HTTPRq.DBChars) < SIZEOF(Page)) THEN
                i:=Sysmemmove(ADR(Page)+Sysstrlen(ADR(Page)), HTTPRq.DBAddress, HTTPRq.DBChars);
            END_IF;
        END_IF;

        // On Done it's possible to test if page has been loaded.

        IF (HTTPRq.Done) THEN
            IF NOT(HTTPRq.PLoad) THEN Errors:=Errors+1; FlipFlop:=FALSE; RETURN; END_IF;

            // Here your public IP address is in the page buffer.

            FlipFlop:=FALSE; //Program Flip/Flop
        END_IF;
    END_IF;

// [End of file]
]]>