title: How to get local IP from Firefox extension code
body: <p>I'm writing a Firefox extension that uses <a href="https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIServerSocket" rel="nofollow noreferrer"><code>nsIServerSocket</code></a> to listen for socket connections. I'm looking for a way for the extension code to programmatically learn the local network address of the machine running the Firefox extension. This information gets communicated to a client on the local network out-of-band such that it can open a socket connection to the extension.</p>
  
  <p>My research into this has so far only turned up individuals wishing to find the ip address <a href="https://stackoverflow.com/questions/1082728/ip-address-lookup-in-a-firefox-extension">of loaded websites</a> by way of <a href="https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIDNSService" rel="nofollow noreferrer">DNS resolution</a> or using <a href="https://stackoverflow.com/questions/1510526/get-the-correct-local-ip-adress-from-java-applet">Java applets</a>) which won't be appropriate for a FF extension. The Mozilla Developer pages on the <a href="https://developer.mozilla.org/En/Using_geolocation" rel="nofollow noreferrer">Geolocation API</a> mentions:</p>
  
  <blockquote>
    <p>"data is exchanged including WiFi Access Point data, an access token (similar to a 2 week cookie), and the user's IP address"</p>
  </blockquote>
  
  <p>but does not indicate an API to access the user's IP address directly.</p>
  
  <p>My only idea at this point is to invoke a local process using <a href="https://developer.mozilla.org/en/nsIProcess" rel="nofollow noreferrer"><code>nsIProcess</code></a> and parse the IP from there. This seems awfully hackish and would have to be handled on a per-OS basis. I.e. do I run ifconfig, netcfg, ipconfig? With what args?</p>
  
  <p>Is anyone aware of a better solution?</p>