简体   繁体   中英

Get LAN IP address from USB tethering network from javascript

I know it sound crazy but I need it.

I found code that gets the public IP address:

<script type="application/javascript">
    function getip(json){
      alert(json.ip); // alerts the ip address
    } </script>

<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>

But that code can't help me here. I do even know if this is possible. But I am looking for the 192.168.42.123 address. How can I found this IP from javascript ?

$ ifconfig

usb0 Link encap:Ethernet HWaddr 6b:fe:56:15:6b:33
inet addr:192.168.42.123 Bcast:192.168.42.255 Mask:255.255.255.0 inet6 addr: fe80::68fe:96ff:fe15:6b49/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1802 errors:0 dropped:0 overruns:0 frame:0 TX packets:2041 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1513563 (1.5 MB) TX bytes:318292 (318.2 KB)

You can't. Whenever he's running your script, the user is on the public network (Internet), and therefore the IP address you'll get through javascript will always be the public one. But you may be taking the problem from the wrong side and doesn't actually need this IP address... there's nothing in it that a remote user could use...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM