Connecting Tech Pros Worldwide Help | Site Map

How can I find the IP address of the local PC ?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2005, 12:02 AM
Arne
Guest
 
Posts: n/a
Default How can I find the IP address of the local PC ?

Hi,

Probably an easy answer to this, but I have not been able to figure it out.

How can I find the IP-address of the machine that my Java-program is running
on ? Could not find any methods in the InetAddress class that does this. The
closest I got was the getLocalHost() which will return the IP-address
representing the loopback address (usually 127.0.01, isn't it ?).

Any ideas ?

Regards
Arne



  #2  
Old July 18th, 2005, 12:02 AM
Christopher Browne
Guest
 
Posts: n/a
Default Re: How can I find the IP address of the local PC ?

Quoth "Arne" <arne@styve.org>:[color=blue]
> Hi,
>
> Probably an easy answer to this, but I have not been able to figure it out.
>
> How can I find the IP-address of the machine that my Java-program is running
> on ? Could not find any methods in the InetAddress class that does this. The
> closest I got was the getLocalHost() which will return the IP-address
> representing the loopback address (usually 127.0.01, isn't it ?).
>
> Any ideas ?[/color]

There can be no easy answer to this, because there is no guarantee
that there is a unique answer to this.

After all, if there are two NICs connected to the machine, which is
eminently common for the sorts of "server class" systems you might
deploy Java apps on, there will therefore be TWO answers for it to
find, neither preferable.

We have some Dell servers that came to us with no less than 5 NICs.

You are probably trying to solve some problem the wrong way...
--
wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','cbbrowne.com').
http://cbbrowne.com/info/x.html
"The most precisely-explained and voluminously-documented user
interface "rule" can and will be shot to pieces with the introduction
of a single new priority consideration." -- Michael Peck
  #3  
Old July 18th, 2005, 12:02 AM
Alex Molochnikov
Guest
 
Posts: n/a
Default Re: How can I find the IP address of the local PC ?

Look at java.net.NetworkInterface class.

"Arne" <arne@styve.org> wrote in message news:426c12a2$1@proxy....[color=blue]
> Hi,
>
> Probably an easy answer to this, but I have not been able to figure it[/color]
out.[color=blue]
>
> How can I find the IP-address of the machine that my Java-program is[/color]
running[color=blue]
> on ? Could not find any methods in the InetAddress class that does this.[/color]
The[color=blue]
> closest I got was the getLocalHost() which will return the IP-address
> representing the loopback address (usually 127.0.01, isn't it ?).
>
> Any ideas ?
>
> Regards
> Arne
>
>[/color]


  #4  
Old July 18th, 2005, 12:02 AM
Arne
Guest
 
Posts: n/a
Default Re: How can I find the IP address of the local PC ?

Hi Christopher,

Thanks for your reply. I am aware of that one machine can have many
IP-addresses, hence I would be happy if I could get to the list of
IP-addresses, or alternatively the MAC-addresses. Or a third alternative
would be to get the networkname of the computer.

The problem I'm trying to solve is related to a framwork I've created for
remote startup of processes/applications. I have one server PC, which
controlles a number of client PCs. The clients registeres at the server as
soon as the client PC is up running. Depending on the client, the server
assigns a set of processes/applications that the client should be able to
start locally on the client (like Word, Excel, Notpad, or any other SW). All
of this is currently working just fine (using RMI), but in order to make the
client SW as general as possible (I don't want to supply startup arguments
that are special for each client), I was thinking of making it possible for
the client SW to be identical on all clients, but when the client SW starts,
it should read an XML-file common to the entire system, which would specify
(based on some unique ID of the client PC, like one IP address, or a MAC
address or the name of the computer) which processes should be possible to
start on this client PC, and also when, in a larger startup sequence, that
client should start it's process(es).

Hence I think I am stilling trying to solve the overall problem the rigth
way. So if you know how to get to the IP-adress(es) of the PC from Java, I
would be really greatfull.

Arne


"Christopher Browne" <cbbrowne@acm.org> wrote in message
news:BQUae.1373$gA5.94049@news20.bellglobal.com...[color=blue]
> Quoth "Arne" <arne@styve.org>:[color=green]
> > Hi,
> >
> > Probably an easy answer to this, but I have not been able to figure it[/color][/color]
out.[color=blue][color=green]
> >
> > How can I find the IP-address of the machine that my Java-program is[/color][/color]
running[color=blue][color=green]
> > on ? Could not find any methods in the InetAddress class that does this.[/color][/color]
The[color=blue][color=green]
> > closest I got was the getLocalHost() which will return the IP-address
> > representing the loopback address (usually 127.0.01, isn't it ?).
> >
> > Any ideas ?[/color]
>
> There can be no easy answer to this, because there is no guarantee
> that there is a unique answer to this.
>
> After all, if there are two NICs connected to the machine, which is
> eminently common for the sorts of "server class" systems you might
> deploy Java apps on, there will therefore be TWO answers for it to
> find, neither preferable.
>
> We have some Dell servers that came to us with no less than 5 NICs.
>
> You are probably trying to solve some problem the wrong way...
> --
> wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','cbbrowne.com').
> http://cbbrowne.com/info/x.html
> "The most precisely-explained and voluminously-documented user
> interface "rule" can and will be shot to pieces with the introduction
> of a single new priority consideration." -- Michael Peck[/color]


  #5  
Old December 5th, 2005, 05:25 PM
Joseph Dionne
Guest
 
Posts: n/a
Default Re: How can I find the IP address of the local PC ?

Starting in JDK 1.4 you can use NetworkInterface to enumerate all IP addresses
on your server.

Arne wrote:[color=blue]
> Hi,
>
> Probably an easy answer to this, but I have not been able to figure it out.
>
> How can I find the IP-address of the machine that my Java-program is running
> on ? Could not find any methods in the InetAddress class that does this. The
> closest I got was the getLocalHost() which will return the IP-address
> representing the loopback address (usually 127.0.01, isn't it ?).
>
> Any ideas ?
>
> Regards
> Arne
>
>[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.