Solved

Network commands in Java

Posted on 1997-12-03
8
455 Views
Last Modified: 2013-11-15
I want to create an applet that includes network commands such as traceroute, ping, nslookup, whois to make a complete name service utility.

Is there code already for these commands? If so, where? If not, do you think I can do them in pure java? If not, is there a way to include a cgi script so I can include them?
0
Comment
Question by:usul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 150 total points
ID: 1231409

You can't do any of these things in an applet inside
of a browser.  The security managers only let you
connect to the system from which the applet was loaded.

You can do one of two things:

You can create CGI scripts that do this and just have
an interface in Java that does this on the server side
and then passes the data back like this:

URL url;
DataInputStream dis;

url = new URL(getCodeBase().toExternalForm() + "cgi-bin/ping.cgi?host=" + hostText.getText());

//Where hostText is a textfield where the user enters
//the host they want to ping

dis = new DataInputStream(new BufferedInputStream(url.openStream()));

// Just read the return from the ping and output it in a text area

Then you need a CGI on the server side which takes a parameter
and does a ping, traceroute or whatever.  If you want to
maintain state, it gets a bit more complicated.


0
 

Author Comment

by:usul
ID: 1231410
Do you have any experience with Perl for Win32? I'm doing this on my own Win95 personal Web Server because the unix machines at my university don't allow commands in html like:

<!--#exec cgi="<cgi file>" -->

I can't figure out how to do something similar with the Win32 perl. If you know a way to do this without SSI, please tell me what I am doing wrong.
0
 
LVL 4

Expert Comment

by:rembo
ID: 1231411

If you do it the way I showed above, you don't need
server side includes.  You just put the Perl script
in the cgi-bin on your Web server.  

I have done this on Windows.  You can definitely do
it this way.


0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:usul
ID: 1231412
Well, my problem is I'm not too familar with the Win32 version (not to say I'm much of a perl expert anyway).

In Unix, I would to it like this:

#!/bin/sh
/usr/bin/ping '$host'

HOw do I do the same in Perl for Win32?
0
 

Author Comment

by:usul
ID: 1231413
Also, I keep geeting this error:

HTTP/1.0 403 Access Forbidden (Execute Access
Denied - This Virtual Directory does not allow objects
to be executed.)


0
 
LVL 4

Expert Comment

by:rembo
ID: 1231414

I'll get you an example of how to do this in Perl.

However, for the Virtual Directory part, you'll need
to configure that directory to allow for CGI, or you'll
need to change the code to work more like this code:

                                host = getCodeBase().getHost();
                                port = getCodeBase().getPort();

                                if (port != 80)
                                        portNum = ":" + port;

                                url2 = new URL("http://" + host + portNum + "/"
+ cgi + "?VTYPE=" + vtype + "&" + sb.toString());
                                getAppletContext().showDocument(url2);
                                System.out.println("Sending: " + url2);
                        } catch (Exception ex) {
                                System.out.println(ex.getMessage());
                        }                                                      
0
 

Author Comment

by:usul
ID: 1231415
Couple of more questions:

How do you get the DataInputScream to return the results? The only thing I could get it to do is return the contents of the file.

Also, when I try to run this script in Netscape 3.01, it prompts me to save the .pl file. How can I get it to print results to screen (this is kinda off-topic I guess)
0
 
LVL 4

Expert Comment

by:rembo
ID: 1231416

If you just want to read the output from the CGI,
you create the url like above, then you do:

DataInputStream dis;

dis = new DataInputStream(url2.openStream());


I'll get you that CGI too...



0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question