how to get IP address (eth0)

Asked by patikal

I want to get the IP address of my machine (static LAN address configured for eth0) in java. The following code on Windows works, but not on UBUNTU. Any setup in UBUNTU needed?
String IpAddress = (InetAddress.getLocalHost().getHostAddress());
shankar

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gnome-nettool Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bhavani Shankar (bhavi) said :
#1

Hello Shankar..

In ubuntu you can find out IP Addresses using ifconfig command with grep and other filters..

Copy and paste the below in a terminal (applications -> accessories -> terminal)

/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

Regards

Bhavani Shankar.

Revision history for this message
patikal (patikal) said :
#2

Hi, Thank you for the answer. Though it gives the required info, i wanted the same java code to work for both Windows and Unix. It is a customer requirement.
Hence need a different answer.
regards
shankar
> To: <email address hidden>> From: <email address hidden>> Subject: Re: [Question #27027]: how to get IP address (eth0)> Date: Fri, 14 Mar 2008 14:01:31 +0000> > Your question #27027 on gnome-nettool in ubuntu changed:> https://answers.edge.launchpad.net/ubuntu/+source/gnome-nettool/+question/27027> > Status: Open => Answered> > Bhavani Shankar proposed the following answer:> Hello Shankar..> > In ubuntu you can find out IP Addresses using ifconfig command with grep> and other filters..> > Copy and paste the below in a terminal (applications -> accessories ->> terminal)> > /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print> $1}'> > Regards> > Bhavani Shankar.> > -- > If this answers your question, please go to the following page to let us> know that it is solved:> https://answers.edge.launchpad.net/ubuntu/+source/gnome-nettool/+question/27027/+confirm?answer_id=0> > If you still need help, you can reply to this email or go to the> following page to enter your feedback:> https://answers.edge.launchpad.net/ubuntu/+source/gnome-nettool/+question/27027> > You received this question notification because you are a direct> subscriber of the question.
_________________________________________________________________
Post free property ads on Yello Classifieds now! www.yello.in
http://ss1.richmedia.in/recurl.asp?pid=220

Revision history for this message
Bhavani Shankar (bhavi) said :
#3

Means you need to run Java Code...

this link gives more info about java on ubuntu:

https://help.ubuntu.com/community/Java

Regards

Bhavani Shankar.

Can you help with this problem?

Provide an answer of your own, or ask patikal for more information if necessary.

To post a message you must log in.