Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Network commands in Java

Posted on 1997-12-03
8
Medium Priority
?
459 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 300 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

721 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