How to get the path of remotly run application by knowing the port number

S

sundy.jk

Hi,
I am new to this group, and i request you all to help in solving the
issues i have.
Thank you for having this group.
I need to know the path or install directory of an application,
I am able to access the the application by port number.
but i need to wright a java programe thr which i need to get the path
or install directory of the application.
Eg
http://servername:2000/
I request you all to help in the same.
 
A

Arnaud Berger

Hi,

Sorry you can't do such thing.
Any application may open ports, and knowing about open ports will never help
you find
where the application is ran from or installed in.

Regards,

Arnaud
 
Y

Yu SONG

Hi,
I am new to this group, and i request you all to help in solving the
issues i have.
Thank you for having this group.
I need to know the path or install directory of an application,
I am able to access the the application by port number.
but i need to wright a java programe thr which i need to get the path
or install directory of the application.
Eg
http://servername:2000/
I request you all to help in the same.

Whether telling you the internal path or not is decided by "the
application" on the server.


--
Song

/* E-mail.c */
#define User "Yu.Song"
#define At '@'
#define Warwick "warwick.ac.uk"
int main() {
printf("Yu Song's E-mail: %s%c%s", User, At, Warwick);
return 0;}

Further Info. : http://www.dcs.warwick.ac.uk/~esubbn/
_______________________________________________________
 
J

John McGrath

i need to wright a java programe thr which i need to get the path
or install directory of the application.

Because of the way that Java loads classes, it is impossible to do this in
the general case. Java classes are loaded by an instance of a subclass of
ClassLoader. How the subclass loads the class is not specified. While
the standard ClassLoaders load classes from a directory or a JAR file,
others could load it from anywhere. You could even have a ClassLoader
that writes the code on the fly.

But while you cannot make this work for *all* cases, you may be able to
make it work for all cases that matter to you. Assuming that your main
program class is called Main, the following expression will give you a URL
for the location it was loaded from:

Main.class.getProtectionDomain().getCodeSource().getLocation();

If your Main class is loaded from a JAR file, this will give you the URL
for the JAR file itself. If your class is loaded from a directory, this
will give you the root directory of the class tree.

If you use this, do not design your application so that it is absolutely
required - it may be that you cannot get the value. This is reasonable
for choosing a default directory, but make sure there are alternate means
of specifying directories. I understand that there are circumstances
where you will have a null CodeSource, although I have never figured out
how to cause that. And be certain to bullet-proof the code - test for
null return values from all of these methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top