What can I do to find the localhost address?

S

Sergio Juan

Hi.

We have a configuration program for a server where the IP of the local
machine is needed. We try to get it from InetAddress.getLocalHost(), but
sometimes it just returns 127.0.0.1 (the IP is passed to other servers so
they can connect with ours).

I have read about sun.net.spi.nameservice.provider and related properties,
but it looks like they are available only since version 1.4 (we need it
working on java 1.3.1). Am I right (in the fact that we cannot use
sun.net.spi.nameservice.provider in 1.3.1)? If I am, has anybody a idea of
how can we get the real IP of the localhost?

TIA. Sergio.
 
J

Joseph Dionne

Sergio said:
I have read about sun.net.spi.nameservice.provider and related properties,
but it looks like they are available only since version 1.4 (we need it
working on java 1.3.1). Am I right (in the fact that we cannot use
sun.net.spi.nameservice.provider in 1.3.1)? If I am, has anybody a idea of
how can we get the real IP of the localhost?

Check the docs on class NetworkInterface. It provides an enum list of
NIC cards installed.
 
S

Steve W. Jackson

Joseph Dionne said:
:Sergio Juan wrote:
:> I have read about sun.net.spi.nameservice.provider and related properties,
:> but it looks like they are available only since version 1.4 (we need it
:> working on java 1.3.1). Am I right (in the fact that we cannot use
:> sun.net.spi.nameservice.provider in 1.3.1)? If I am, has anybody a idea of
:> how can we get the real IP of the localhost?
:>
:
:Check the docs on class NetworkInterface. It provides an enum list of
:NIC cards installed.
:

OP asked for 1.3.1 compatibility. This class was added as of 1.4.
 
J

Joseph Dionne

Steve said:
OP asked for 1.3.1 compatibility. This class was added as of 1.4.

Sorry, you are correct. However, the NetworkInterface is the "fix" to
the sort comings of "net" package of Java 1.3. I should have answered
the question directly; I will do so now.

No, in Java 1.3.x you will not be able to accurately get the local
installed IP addresses. You will need to migrate to Java 1.4, or write
you own JNI to emulate what NetworkInterface does.
 
M

marcus

This has always worked for me on various windows platforms and JVM's,
and on my unix system:

import java.io.*;
import java.net.*;


public class whoami{
public static void main(String[] args) {
try{
System.out.println("hello whoami\n");
InetAddress i = InetAddress.getLocalHost();
System.out.println(i.getHostAddress()+"\n");

} catch(UnknownHostException e){}
}


}
 
M

marcus

Um, my wife called me to dinner and I f*cked it up hehe

import java.io.*;
import java.net.*;


public class whoami{
public static void main(String[] args) {
try{
System.out.println("hello whoami\n");
InetAddress i = InetAddress.getLocalHost();
System.out.println(i.getHostAddress()+"\n");
i=InetAddress.getByName(i.getHostName());
System.out.println(i.getHostAddress()+"\n");
} catch(UnknownHostException e){}
}


}
The second level of indirection should force a DNS query using the
socket stack of whatever OS is running. DNS should never return
localhost for the local host, as it were.

and even though I have been using usenet for years, I top-post for googlers

This has always worked for me on various windows platforms and JVM's,
and on my unix system:

import java.io.*;
import java.net.*;


public class whoami{
public static void main(String[] args) {
try{
System.out.println("hello whoami\n");
InetAddress i = InetAddress.getLocalHost();
System.out.println(i.getHostAddress()+"\n");

} catch(UnknownHostException e){}
}


}

Joseph said:
Check the docs on class NetworkInterface. It provides an enum list of
NIC cards installed.
 
A

Andrew Thompson

marcus said:
Um, my wife called me to dinner and I f*cked it up hehe

yeah sure.. blame the wife. ;-)

and even though I have been using usenet for years, I top-post for
googlers

Well, well. A _third_ reason for
top-posting, beyond..
a) I am blind
b) I use Otutlook Express

The thing is, Marcus, with judicious editing
(something that can _also_ be done when
top-posting), the important bits of responses
can be very near the top of a message in any
case.

...Even assuming google did _not_ highlight
the relevant part of any message found.

While you have a reason for top-posting -
it is not a compellingly convincing one.
 
M

marcus

OK, I admit it was a bit of a troll, but it was in response to an
earlier reply in this newsgroup that stated the writer actually
corrected someone's top post. That is offensive to me.

Google cuts off after so many lines in threaded view, so to read the
entire reply you have to break out of the view into another. Makes it
very difficult to maintain your place. And since many people in this
newsgroup advise googling for an answer, it kinda made sense.

Further, this group more than most I read ends up having multi-hundred
line posts. Since so many people edit the bulk when making replies, the
previous posts have to be read thoroughly anyway -- you can't simply
read through the last one to pick up on the gist because it may have
been chopped several times.

Hmm, since each one has to be read, why scan through hundreds of lines
of bulk to get to the juicy stuff?

And your compelling reason for bottom posting is what? I bottom posted
for many years, now I top post. Bottom posting was fine IMHO back in
the day when posts were a couple of paragraphs and no one chopped.

Cheers!
 
H

Harald Hein

marcus said:
Google cuts off after so many lines in threaded view, so to read the
entire reply you have to break out of the view into another.

Who cares what google does? The established standard on usenet is not
to top-post.
 
G

Gregory A. Swarthout

Harald Hein said:
Who cares what google does? The established standard on usenet is not
to top-post.

I find explanations of "it has always been thus" to be suspect. As
another usenet-er who exclusively uses Google as his reader, I find
his explanation for top-posting convincing, not to mention useful.
 
A

Andrew Thompson

Gregory A. Swarthout said:
Harald Hein <[email protected]> wrote in message .....
...As
another usenet-er who exclusively uses Google as his reader, I find
his explanation for top-posting convincing, not to mention useful.

So you missed Google's links to..
'Read the rest of this message... (nn more lines)'?

The thing is, a lot of significant posts (containing
example code for instance) are longer than what
Google will show in the initial thread.

That link to the full message invalidates the
entire 'do it for Google' argument.
 
G

Gregory A. Swarthout

Andrew Thompson said:
So you missed Google's links to..
'Read the rest of this message... (nn more lines)'?

Not at all.
The thing is, a lot of significant posts (containing
example code for instance) are longer than what
Google will show in the initial thread.

That link to the full message invalidates the
entire 'do it for Google' argument.

No, it doesn't. Having to link into and back out of each message makes
it cumbersome to read a thread through Google.

Greg
 
A

Andrew Thompson

....
No, it doesn't. Having to link into and back out of each message makes
it cumbersome to read a thread through Google.

You _poor_ thing!

So, what do you do for the long posts?
Shrug your shoulders and rue the fact that
you will never know that information because
Google (Damn Them!) do not show the entire
article in the _initial_ _thread_?

If the 'cut-off' justifies anything, it's keeping
articles trimmed to the minimum. Keep only
what is relevant and don't waffle.
 
J

Jezuch

U¿ytkownik Gregory A. Swarthout napisa³:
No, it doesn't. Having to link into and back out of each message makes
it cumbersome to read a thread through Google.

Use Mozilla and tabbed browsing.
 
M

Mark 'Kamikaze' Hughes

Gregory A. Swarthout said:
No, it doesn't. Having to link into and back out of each message makes
it cumbersome to read a thread through Google.

The solution is not to mangle posts so you can pretend Google is a
newsreader, but to get a real newsreader. Google's an archive tool.
You're polluters, wasting resources and slowing Google down for everyone
else by misusing it as a regular newsreader.

I recommend <http://slrn.sourceforge.net/>. Or leaving USENET
entirely, whichever is easier for you.
 
M

marcus

Wow, my points vindicated by my detractors.

If you insist I only use a client instead of an archive tool, you can
never suggest I google something before posting. I always research a
question before posting, hence I read google first before using a client
to reply. If you want people to google basic questions before posting,
you have to see google as a valuable and valid tool. If you recognize
as I do that google is a valuable and valid tool, you will begin to see
that enhancing archivableness it a valid goal. Whether or not my
technique is agreeable to you, I have a valid goal. "Who cares what
google does?" only about a hundred million people.

I said since posts are chopped consistantly and have to be read through
individually anyway, top-posting makes more sense in the modern world
than bottom posting. Funny how you missed that part because my post was
chopped.

But for you to say the solution it to not mangle posts, having chopped
mine to shreds, is ironic. Calling me a polluter is comical.

I believe this is what the supreme court referred to recently (I don't
recall who they were quoting) as the "marketplace of ideas." Old ideas
die, new ones supplant them. If that is pollution, well I don't vote
Green anyway.

I find it ironic that anything as young as the concept of newsgroups
(circa 1979) can have such staunch traditionalists. But you type with
capital letters, so you are not that staunch after all.
 
A

Andrew Thompson

marcus said:
Wow, my points vindicated by my detractors.

If you insist I only use a client instead of an archive tool,

_You_ are the only one who has suggested that.

Mark was advising not to use an archive tool as
a newsreader, one might have surmised that he
was suggesting you ..do all of _both_ those things.
Use a newsreader to read news, and the archive
tool for searching.

[ And FTR you, mangling his words, is the
best case against top-posting thus far in this
thread. ]
 
G

Gregory A. Swarthout

The solution is not to mangle posts so you can pretend Google is a
newsreader, but to get a real newsreader. Google's an archive tool.

Actually, it IS a newsreader. The fact that Google maintains an archive is
irrelevant.
You're polluters, wasting resources and slowing Google down for everyone
else by misusing it as a regular newsreader.
Eh?

I recommend <http://slrn.sourceforge.net/>. Or leaving USENET
entirely, whichever is easier for you.

No, thanks. You use USENET your way, and I'll use it mine.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top