🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2999

getting the Local Address

#2999
From: William Yu
Date: Fri, 19 Jun 1998 00:00
20 lines
1543 bytes
Here's another fun question to look at. The goal, of course, is to get
the IP address of the computer on which the Java application or applet
is running on. From what I can tell, there is nothing in the API showing
a simple way to get the local address.

My initial thought was to create a dummy ServerSocket or DatagramSocket
instance and trick it into returning an address. I know that once you
have a socket connection, you can get both the local & host IP address.
So I was hoping that simply creating the instance would let you access
those methods. Unfortunately, my hopes were false.

Right now, my thinking is to create a socket connection to yourself. The
ugly part is where the net commands block until a connection is actually
made. That means you need two threads to connect to each other or you
will never get an answer. The other problem is attempting to make this
into a static method where you can access it from anywhere -- as far as
I can tell, you can't create threads from a static method.

So chime in with the ideas...
Technical Details
Message-ID: <358B241C.30A1A097@Bigfoot.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,a1a9349ee1d4ae68,start
X-Google-Attributes: gid1089d0,public
From: William Yu <William_Yu@Bigfoot.com>
Subject: getting the Local Address
Date: 1998/06/19
Message-ID: <358B241C.30A1A097@Bigfoot.com>
X-Deja-AN: 364381496
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: American All-Risk Group (AARG)
Newsgroups: borland.public.jbuilder.java.api