Solved

Network commands in Java

Posted on 1997-12-03
8
449 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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 article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

821 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