Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to IP address(URGENT)  RSS feed

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have stand alone application running on the server. I want to get IP address of server(that's localhost IP address).
Angela
P.S.:I DON'T WANT TO GET LOCAL HOST NAME. I WANT TO GET LOCAL IP ADDRESS(Format : xx.xx.xx.xx)
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you have win95 or win98 write this on the run method or in dos: winipcfg
if you have win 2000 or me or nt or xp use this line instead: ipconfig
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops. did you mean by API ?
then you need to get first the InetAddress of the ServerSocket by using the method getInetAddress().
the use this method of the InetAddress: getHostAddress() which return the String you want.
or you can use this too:
InetAddress address=InetAddress.getLocalHost();
String ip=address.getHostAddress();
[ March 07, 2002: Message edited by: Roy Ben Ami ]
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roy Ben Ami:
if you have win95 or win98 write this on the run method or in dos: winipcfg
if you have win 2000 or me or nt or xp use this line instead: ipconfig

HOW TO USE THIS COMMANDS IN JAVA APPLICATION.CAN YOU GIVE ME SMALL EXAMPLE?
Thanks a lot,
Angela
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
excuse me for the first example. i misunderstood you.
look at my second post which is correct.
use these lines to get the IP address and print it:
InetAddress address=InetAddress.getLocalHost();
String ip=address.getHostAddress();
System.out.println(ip);
[ March 07, 2002: Message edited by: Roy Ben Ami ]
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I got it!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!