Solved

Network commands in Java

Posted on 1997-12-03
8
442 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
  • 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
 

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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now