Can I get my IP address in a chrome app without using an external service?

前端 未结 3 353
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 06:29

I am building a chrome app and created a UDP socket via the chrome socket api.

Is there a way to retrieve your own IP address without u

3条回答
  •  -上瘾入骨i
    2021-01-22 07:17

    turns out that I have been using the wrong API. For my use case I needed to use chrome.system.network.getNetworkInterfaces.

    This will return an array of all interfaces with their IP address.

    This is my sample code:

    chrome.system.network.getNetworkInterfaces(function(interfaces){
        console.log(interfaces);
    });
    

    manifest-permissions:

    "permissions": [
      "system.network"
    ],
    

    Considering the comments a perfect solution is not easy to provide, as one has to find the correct interface to the UDP-port.

    At this point the only way to perfectly match the interface one has to bind all addresses for all interfaces given by getNetworkInterfaces. Then you know exactly which interface was used to receive the call and you can respond with the correct IP address.

提交回复
热议问题