Article View: borland.public.jbuilder.java.api
Article #1206How to get local IP Address ?
From: Vincent DOYELLE
Date: Sun, 07 Apr 2002 09:53
Date: Sun, 07 Apr 2002 09:53
22 lines
1516 bytes
1516 bytes
I'm running linux redhat 7 with jdk 1.3.1_02 and JB 5.0
I'm trying to get my local IP Address with this code :
InetAddress[] addresses;
addresses =
InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
for (int i=0; i<addresses.length; i++) {
System.out.println(addresses.getHostAddress());
}
}
catch(UnknownHostException e) {
System.out.println (e.getMessage());
}
My problem is that I always get the 127.0.0.1 address.
I'm using DSL to have access to internet.
Is there any way using java api rather than executing system command
(because I've to write a multiplatform program).
Furthermore, is there anay way to get the subnet mask of the local host ?
TIA
Vincent
Technical Details
Message-ID:
<3cb016d0$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!news.cs.utwente.nl!logbridge.uoregon.edu!fu-berlin.de!news.boerde.de!nntp.cs.uni-magdeburg.de!PeerFeed.KWeb.on.ca!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,e2063f566e0de7e5,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-07 03:02:22 PST From: Vincent DOYELLE <vdoyelle@yahoo.fr> Subject: How to get local IP Address ? Newsgroups: borland.public.jbuilder.java.api Date: Sun, 7 Apr 2002 11:53:32 +0200 Lines: 22 User-Agent: KNode/0.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit NNTP-Posting-Host: 80.11.207.69 Message-ID: <3cb016d0$1_1@dnews> X-Trace: dnews 1018173136 80.11.207.69 (7 Apr 2002 01:52:16 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!news.cs.utwente.nl!logbridge.uoregon.edu!fu-berlin.de!news.boerde.de!nntp.cs.uni-magdeburg.de!PeerFeed.KWeb.on.ca!dnews