22

我正在寻找一种方法来做一个跟踪路由客户端,即在浏览器中。

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

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

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

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

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

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

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

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

4

8 回答 8

7

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.

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.

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.

于 2010-02-03T22:59:45.427 回答
5

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

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

由于安全限制,Javascript 和 Actionscript 无法执行此操作。它们仅存在于网页上下文中。Silverlight 可能能够做到,但不要把我钉在那个上面。我不做 NET 的东西。

于 2010-02-03T12:31:19.803 回答
3

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

Chrome extension: https://chrome.google.com/extensions/detail/mmkpilpdijdbifpgkpdndpjlkpjkihee Firefox add-on: 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.

于 2010-07-07T13:07:57.847 回答
1

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

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

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

于 2010-02-03T12:19:20.110 回答
0

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

于 2010-02-03T12:22:06.763 回答
0

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

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

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

于 2011-05-13T06:32:35.423 回答
0

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

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

UPD: seems like it only works in Firefox

于 2012-01-14T16:33:54.877 回答
0
<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.

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

于 2016-02-29T09:15:56.693 回答