Article View: borland.public.jbuilder.java.api
Article #1207Re: How to get local IP Address ?
From: Owen Green
Date: Sun, 07 Apr 2002 11:22
Date: Sun, 07 Apr 2002 11:22
24 lines
1677 bytes
1677 bytes
Vincent DOYELLE <vdoyelle@yahoo.fr> wrote in message
news:3cb016d0$1_1@dnews...
> InetAddress[] addresses;
> addresses =
> InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
> for (int i=0; i<addresses.length; i++) {
> System.out.println(addresses.getHostAddress());
> }
> }
Shouldn't that be addresses[i].getHostAddress() ?
Otherwise that should work. What does
InetAddress.getLocalHost().getHostName() return?
If I do the exactly the above I get my machine's host name and proper DHCP
IP address, if I put in 'localhost' I get 127.0.0.1.
> Furthermore, is there anay way to get the subnet mask of the local host ?
Not without resorting to Runtime.exec() or JNI AFAIK.
hth
Owen
Technical Details
Message-ID:
<3cb02aab_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!news.infoave.net!newsfeed.frii.com!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3cb016d0$1_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,e2063f566e0de7e5 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-07 04:21:47 PST From: "Owen Green" <owen@begonefoulmachine.kennulz.demon.co.uk> Newsgroups: borland.public.jbuilder.java.api References: <3cb016d0$1_1@dnews> Subject: Re: How to get local IP Address ? Date: Sun, 7 Apr 2002 12:22:54 +0100 Lines: 26 Organization: Unique Interactive X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 217.134.225.182 Message-ID: <3cb02aab_2@dnews> X-Trace: dnews 1018178219 217.134.225.182 (7 Apr 2002 04:16:59 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!news.infoave.net!newsfeed.frii.com!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews