Solved

Network commands in Java

Posted on 1997-12-03
8
446 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
The viewer will learn how to implement Singleton Design Pattern in Java.

813 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

12 Experts available now in Live!

Get 1:1 Help Now