How to get the path of remotly run application by knowing the port number  
Author Message
sundy.jk@gmail.com





PostPosted: 2005-4-4 18:08:00 Top

java-programmer, How to get the path of remotly run application by knowing the port number 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.

 
Arnaud Berger





PostPosted: 2005-4-4 18:14:00 Top

java-programmer >> How to get the path of remotly run application by knowing the port number 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

<email***@***.com> a 閏rit dans le message news:
email***@***.com...
> 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.
>


 
Yu SONG





PostPosted: 2005-4-4 19:49:00 Top

java-programmer >> How to get the path of remotly run application by knowing the port number email***@***.com wrote:
> 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/
_______________________________________________________

 
 
John McGrath





PostPosted: 2005-4-5 13:41:00 Top

java-programmer >> How to get the path of remotly run application by knowing the port number On 4/4/2005 at 6:07:53 AM, email***@***.com wrote:

> 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.

--
Regards,

John McGrath