如何使用Javascript获取本地网络中所有有效IP地址的列表? [英] How to get a list of all valid ip address in a local network using Javascript?
问题描述
我为移动设备编写了一个jQuery mobile / Cordova应用程序,该应用程序可以连接(例如通过WiFi)到特定的本地网络(LAN),他有一个服务器可以提供应用程序可能使用的一些服务一些JSON数据来填充本地存储)。
I'm writing a jQuery mobile/Cordova application for a mobile device, who can connect (say by WiFi) to a particular local network (LAN), who has a server that can provide some service that the app may use (some JSON data to populate a local storage).
在给定的时刻,可以有几个设备在网络上连接。说:
In a given moment there can be several devices connected at the network. Say:
192.168.1.33
192.168.1.35
192.168.1.38
...
但是服务器没有固定IP(取决于唤醒到LAN)其IP可以
But the server not have a constant IP (depending on the wake up to the LAN) its IP can vary in a range.
问题是:如何获取可见IP的列表,依次尝试从服务器获取服务?
The question is: how can get a list of the visibles IPs, to try in turn, get the service from the server?
推荐答案
我曾经遇到过类似的挑战。我做的是:
I once faced a similiar challange. What I did was:
- 实现一个
/ ping
响应客户端。 - 因此,客户端仅调用自己IP地址范围内的所有IP(例如
192.168.178.1/ping
到192.168.178.254/ping
),如果有响应: - 您找到了您的服务器。
- Implementing a
/ping
serverwise that returns a json formatted response to the client. - So the "Client" just calls all IPs in own IP-Adress range (e.g.
192.168.178.1/ping
to192.168.178.254/ping
) and in case there is a response: - You found your server.
目前未被任何客户端使用的IP都不会造成任何损害,因此无需找出哪些IP有效。需要代码吗?
IPs that are currently not taken by any client do no harm - so no need to find out which ones are valid. Code needed?
这篇关于如何使用Javascript获取本地网络中所有有效IP地址的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!