Java 是否可以在浏览器中进行跟踪路由?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2177431/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:27:00  来源:igfitidea点击:

Is it possible to do a traceroute in the browser?

javajavascriptactionscriptclient-sidetraceroute

提问by Franck

I'm looking for a way to do a traceroute client-side, i.e. in a browser.

我正在寻找一种方法来执行 traceroute 客户端,即在浏览器中。

As far as I know, it's not possible to send ICMP, UDP or TCP packets with arbitrary TTL values via Javascript or Flash. I know Flash allows TCP connections via the Socket class in Actionscript but it doesn't seem useful for a traceroute implementation.

据我所知,不可能通过 Javascript 或 Flash 发送具有任意 TTL 值的 ICMP、UDP 或 TCP 数据包。我知道 Flash 允许通过 Actionscript 中的 Socket 类进行 TCP 连接,但它似乎对跟踪路由实现没有用。

Is the only solution to develop a browser plug-in ?

开发浏览器插件是唯一的解决方案吗?

EDIT: I just found out that it has been done with a Java applet: http://www.codefromthe70s.org/traceroute.aspx

编辑:我刚刚发现它是用 Java 小程序完成的:http: //www.codefromthe70s.org/traceroute.aspx

The bad news is that this applet requires to be signed code because it actually parses the output from the ping executable of the underlying client system. Because of this, the user is asked to allow the Java application to run, which is cumbersome.

坏消息是这个小程序需要签名代码,因为它实际上解析来自底层客户端系统的 ping 可执行文件的输出。正因为如此,要求用户允许Java应用程序运行,这很麻烦。

More info here: http://www.codefromthe70s.org/traceroute_explained.aspx

更多信息:http: //www.codefromthe70s.org/traceroute_explained.aspx

I am still looking for a simpler solution if anyone can help.

如果有人可以提供帮助,我仍在寻找更简单的解决方案。

EDIT 2: Thanks for your answers. I guess I'll have to go with Java then.

编辑 2:感谢您的回答。我想那时我将不得不使用 Java。

I wonder if NaCl ( http://code.google.com/p/nativeclient/) would support some kind of traceroute app.

我想知道 NaCl ( http://code.google.com/p/nativeclient/) 是否会支持某种 traceroute 应用程序。

采纳答案by Marc B

You can't do this at all from a browser. Javascript can at best open a connection back to its originating server for AJAX requests, but can only do so via HTTP. Flash can talk to arbitrary hosts, but only if they're listed in a crossdomain.xml file on the originating server, and again only via TCP. UDP support in Flash is apparently pending.

您根本无法通过浏览器执行此操作。Javascript 最多可以为 AJAX 请求打开一个回其原始服务器的连接,但只能通过 HTTP 执行此操作。Flash 可以与任意主机通信,但前提是它们列在原始服务器上的 crossdomain.xml 文件中,并且只能通过 TCP。Flash 中的 UDP 支持显然是待定的。

Traceroute and ping are both ICMP-based protocols and cannot be created/controlled from Flash or Javascript. They also both require 'raw' access to build custom packets, and this definitely cannot be done browser-side. This is why 'ping' is an 'SUID' program on Unix systems, as raw packet access requires root privileges.

Traceroute 和 ping 都是基于 ICMP 的协议,不能从 Flash 或 Javascript 创建/控制。它们也都需要“原始”访问来构建自定义数据包,这绝对不能在浏览器端完成。这就是为什么 'ping' 在 Unix 系统上是一个 'SUID' 程序,因为原始数据包访问需要 root 权限。

At best you can do a server-side implementation and have the output sent to the browser. And even then, you most likely could not do it from an in-server process on a Unix box, as the web server is unlikely to be running as root. You'd have to execute the system ping and/or traceroute and redirect the output back to the browser.

充其量您可以执行服务器端实现并将输出发送到浏览器。即便如此,您很可能无法从 Unix 机器上的服务器内进程执行此操作,因为 Web 服务器不太可能以 root 身份运行。您必须执行系统 ​​ping 和/或 traceroute 并将输出重定向回浏览器。

回答by Rich

Hmm... no, because of the security model.

嗯...不,因为安全模型。

You mightbe able to do it in a particular browser with a plug-in, but not an arbitrary browser using anything widely available.

可能可以在带有插件的特定浏览器中执行此操作,但不能在使用任何广泛可用的任何浏览器的任意浏览器中执行此操作。

I'd like to be proven wrong here.

我想在这里被证明是错误的。

回答by Ilian Iliev

How about executing traceroute on the server and returning the result with somekind of ajax call

如何在服务器上执行 traceroute 并通过某种 ajax 调用返回结果

回答by BalusC

Why don't you justsign the applet? Isn't the problem actually more you don't know how to sign the applet? If so, then start here: jarsigner. Hereis a more clear tutorial.

你为什么不直接签署小程序?问题是不是其实更多的是你不知道怎么给小程序签名?如果是这样,那么从这里开始:jarsigner是一个更清晰的教程。

There is actually no simpler/better solution than actuallyrunning some piece of code and/or commands at the client machine. The traceroute really have to originate at the client machine.

实际上没有比在客户端机器上实际运行一些代码和/或命令更简单/更好的解决方案。traceroute 确实必须源自客户端计算机。

Javascript and Actionscript cannot do this due to security restrictions. They lives in the webpage context only. Silverlight might be able to do, but don't pin me on that. I don't do NET stuff.

由于安全限制,Javascript 和 Actionscript 无法执行此操作。它们只存在于网页上下文中。Silverlight 或许能够做到,但不要把我固定在这一点上。我不做网络的东西。

回答by Vojtech Vitek

There is CoNetServ (Complex Network Services) browser extension. It is able to do traceroute from your local machine straight in your browser. https://github.com/VojtechVitek/CoNetServ/wiki

有 CoNetServ(复杂网络服务)浏览器扩展。它可以直接在浏览器中从本地机器执行 traceroute。 https://github.com/VojtechVitek/CoNetServ/wiki

Chrome extension: https://chrome.google.com/extensions/detail/mmkpilpdijdbifpgkpdndpjlkpjkiheeFirefox add-on: https://addons.mozilla.org/en-US/firefox/addon/181909/

Chrome 扩展:https: //chrome.google.com/extensions/detail/mmkpilpdijdbifpgkpdndpjlkpjkiheeFirefox 插件:https: //addons.mozilla.org/en-US/firefox/addon/181909/



EDIT:Both Chrome and Firefox revoked bundling NPAPI libraries into the extensions/add-ons. Unfortunately, the above won't work anymore.

编辑:Chrome 和 Firefox 都取消了将 NPAPI 库捆绑到扩展/附加组件中。不幸的是,以上将不再起作用。

回答by mTorres

Maybe a little late, but could be interesting for future readings (like mine :-D).

也许有点晚了,但对未来的阅读可能很有趣(比如我的:-D)。

Java 1.5 has a InetAdress Class with a isReachable method, that you can try. Check this:

Java 1.5 有一个带有 isReachable 方法的 InetAdress 类,您可以尝试一下。检查这个:

http://download.oracle.com/javase/1.5.0/docs/api/java/net/InetAddress.html#isReachable(int)

http://download.oracle.com/javase/1.5.0/docs/api/java/net/InetAddress.html#isReachable(int)

回答by myfreeweb

You don't need to create an applet and sign it! It's possible to use java from javascript. I made a scriptfor doing a traceroute with ActiveX or Java.

您无需创建小程序并对其进行签名!可以从 javascript 使用 java。 我制作了一个脚本,用于使用 ActiveX 或 Java 进行跟踪路由。

I don't see any security warnings on OS X. Try it on Windows and Linux and tell me what happens :-)

我在 OS X 上没有看到任何安全警告。在 Windows 和 Linux 上尝试一下,然后告诉我会发生什么:-)

UPD:seems like it only works in Firefox

UPD:似乎它只适用于 Firefox

回答by Ярослав Исаев

<script type="text/javascript">
        function runapp() {
        var domain = "10.10.35.1";
        var cmdLine = "tracert" +" " + domain; 
        var wshShell = new ActiveXObject("WScript.Shell"); 
        var out = wshShell.Exec(cmdLine); 
        var output1 = out.StdOut.ReadAll();
        document.getElementById('box').innerHTML += output1;
        }

     </script>

<div id="box" align="center"></div>
    <button onclick="runapp();">Click me!</button>

So it works only in IE because of ActiveX.

因此,由于 ActiveX,它只能在 IE 中工作。

It'll run traceroute to 10.10.35.1 and write output to div with id="box".

它将运行 traceroute 到 10.10.35.1 并将输出写入 id="box" 的 div。