Is it possible to do a traceroute in the browser?

独自空忆成欢 提交于 2019-12-02 21:42:57

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.

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

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

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.

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

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.

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

You might be 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.

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

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)

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

<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".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!