简体   繁体   English

从Javascript从USB共享网络获取LAN IP地址

[英]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: 我找到了获取公共IP地址的代码:

<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. 但是我正在寻找192.168.42.123地址。 How can I found this IP from javascript ? 如何从javascript中找到该IP?

$ ifconfig $ ifconfig

usb0 Link encap:Ethernet HWaddr 6b:fe:56:15:6b:33 usb0 Link encap:以太网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) inet地址:192.168.42.123广播:192.168.42.255掩码:255.255.255.0 inet6地址:fe80 :: 68fe:96ff:fe15:6b49 / 64范围:链接向上广播运行多播MTU:1500指标:1 RX数据包:1802错误: 0掉落:0超限:0帧:0 TX数据包:2041错误:0掉落:0超限:0载波:0冲突:0 txqueuelen:1000 RX字节:1513563(1.5 MB)TX字节: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. 每当他运行您的脚本时,该用户就位于公共网络(Internet)上,因此您将通过javascript获取的IP地址将始终是公共地址。 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... 但是您可能是从错误的角度考虑问题,实际上并不需要此IP地址...其中没有任何远程用户可以使用的IP地址...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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