Can I get the device's WiFi or host name, local IP or other device identifier?

I’m using a WebApp (not referring to a webview), to display data on a large screen. The data itself is irrelevant.

What I need to do is have the WebApp get some data from either the device (Raspberry Pi running Chrome) or the local network, that tells the WebApp something unique about this device that is running the WebApp.

For example, the local IP, or a device ID that I can reference in the WebApp itself. If Push Notifications worked I could use the OneSignal ID. But it doesn’t.

I saw actech’s demo app that gets some device data and IP via AJAX, but that isn’t specific to the device.

The route I would like to have is:
device starts > WebApp runs on chrome > WebApp looks for device specific info > checks with database > displays data relevant to that device.

The thing is, because it’s all remote I can’t just set it up again if the power goes off etc. which is why I need the device to identify itself, without human interaction.
If it was running as an app i.e. on a mobile there would be no problem, I could use OneSignal or just ensure persistent storage, or both.
But with a WebApp, it has to survive power failures and reboots. Which this does not.

I tried putting the WebApp in an iframe and getting the parent URL using a webview (and JS), and having the iframe set to referrerpolicy=strict-origin or unsafe-url, but that doesn’t work.

I also can’t use ThunkableWebviewerExtension.postMessage to post into an iframe from the host page. the postMessage has to be within a webview already in the WebApp, which is not what I need.

Basically; is there anyway to get external device or local information into the app?

Thank you.

1 Like

The easiest is to use the Web API component and use https://api.ipify.org/ or https://api.ipify.org?format=json.

This will return the local IP address of the machine/device.

1 Like

Hi,

This gets the public IP address, I’m looking for my internal one i.e. 192.168.1.123

What I meant by external device info in the above post was data from outside the webapp, not the external IP, sorry for any confusion.

I did some reading and it seems like getting the local IP through any kind of API (or even JS) is a security issue and unsupported by most methods.

So I’m looking into alternatives such as:

  1. Running android on the raspberry pi so I can export the android app and use one-signal’s ID to register the device
  2. Creating separate projects (though I already have 50 apps…)
1 Like

I looked into the issue and basically, reading the local IP of the client is regarded a security issue.

To go around it you can do one of two solutions

  • Write a PHP script to listen to client requests and return back the client IP and load it in your server. then create a JavaScript code to request info from the server to get the client IP.

  • In chrome, by default the local IP is hidden. use the chrome;//flags to disable this feature


    Then use webTRC calls to read the local IP.

You may test with this sample code.

<!DOCTYPE html>
<html>
  
<head>
    <title>Getting Clients IP</title>
</head>
    <body>
        <div id="list"></div>  
        <script >  

        const ip = new Promise((resolve, reject) => {
        const conn = new RTCPeerConnection()
        conn.createDataChannel('')
        conn.createOffer(offer => conn.setLocalDescription(offer), reject)
        conn.onicecandidate = ice => {
            if (ice && ice.candidate && ice.candidate.candidate) {
                document.getElementById('list').innerHTML = ice.candidate.candidate.split(' ')[4];
            resolve(ice.candidate.candidate.split(' ')[4])
            conn.close()
            }
        }
        })
        </script>   
    </body>
</html>

Note that when this feature is enabled, you will get a long alphanumeric string with .local at the end.
bbc39f77-55e0-47c5-9975-96819229c21a.local

Hope this helps.

1 Like

What platform to write on?

What’s this?

1 Like

This is platform independent. It will show when you run the JavaScript I attached instead of the local IP address but if you disable the option I showed you and run the script again, you will see the local IP address.

ok now going for a test.

1 Like

If you are connected via a WIFI then you can do the test by executing the script in one tab and see the output while in the other tab run https://api.ipify.org/

ipify will always give the internet provider IP address while the script I shared will give the WIFI IP address only when the Anonymize local IP exposed by WebRTC option is disabled. If the option is enabled then you will get this long arbitrary number ending with .local

Have fun.

ok now.


:angry:how dare you find my IP adress!

@super-coder just google “my ip” and it will tell you, there are millions of websites that log your IP address, even Google Analytics does it.

It’s no secret, probably 95%+ of websites you visit will monitor/log your IP address, including this forum.

2 Likes

whatever this is solved and no other solutions are aceepted again.