使用 Javascript ping ip 地址列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17961486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ping list of ip addresses using Javascript
提问by user2636553
I have a list of ip addresses to ping and would like to use Java script to do that.
我有一个要 ping 的 ip 地址列表,并希望使用 Java 脚本来执行此操作。
I tried as the following but there is no output when I clicked the "Test" button.
我尝试了以下操作,但是当我单击“测试”按钮时没有输出。
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
function myFunction()
{
var myStringArray = [ "10.100.200.133", "10.10.22.0" ];
len=myStringArray.length
for (var i=0; len=myStringArray.length; i<len; i++) {
check=ping(i)
if $check Then
document.write("ip"+ i + "is up")
else
document.write("ip"+ i + "is down")
}
}
</script>
</head>
<body>
<button onclick="myFunction()">Test</button>
</body>
</html>
回答by Lonely
You can't directly "ping" in JavaScript. There may be a few other ways:
你不能在 JavaScript 中直接“ping”。可能还有其他几种方式:
Ajax
Using a Java applet with isReachable
Writing a server-side script which pings, and using AJAX to communicate to your server-side script
You might also be able to ping in Flash (using ActionScript)
There are also some methods for pinging in JavaScript described in this question: Is it possible to ping a server from Javascript?
阿贾克斯
使用带有 isReachable 的 Java 小程序
编写一个可以 ping 的服务器端脚本,并使用 AJAX 与您的服务器端脚本通信
您也许还可以在 Flash 中 ping(使用 ActionScript)
在这个问题中还描述了一些在 JavaScript 中 ping 的方法:Is it possible to ping a server from Javascript?
回答by SheetJS
ping has a very specific meaning: https://tools.ietf.org/html/rfc1122#section-3.2.2.6, which cannot be replicated using a browser API.
ping 具有非常具体的含义:https: //tools.ietf.org/html/rfc1122#section-3.2.2.6,无法使用浏览器 API 进行复制。
If you want to just test if a web page hosted at a particular IP is available, you can use XMLHttpRequest
如果您只想测试托管在特定 IP 上的网页是否可用,您可以使用XMLHttpRequest