getLocalHost returns a strange IP

A

Aaron Fude

Hi,

The result of calling

java.net.InetAddress.getLocalHost().getHostAddress()

on my machine is:

169.254.221.10

Now, my machine is on a LAN with IP 192.168.1.3 and the external
router IP is something altogether different.

Where in the world does "169.254.221.10" come from?

Thanks!

Aaron
 
R

RedGrittyBrick

Aaron said:
Hi,

The result of calling

java.net.InetAddress.getLocalHost().getHostAddress()

on my machine is:

169.254.221.10

Now, my machine is on a LAN with IP 192.168.1.3 and the external
router IP is something altogether different.

Where in the world does "169.254.221.10" come from?

A computer typically has many IP addresses.

Depending on o/s try "ipconfig -a" or "ifconfig /all" at the command prompt.
 
D

Dave Miller

Aaron said:
Hi,

The result of calling

java.net.InetAddress.getLocalHost().getHostAddress()

on my machine is:

169.254.221.10

Now, my machine is on a LAN with IP 192.168.1.3 and the external
router IP is something altogether different.

Where in the world does "169.254.221.10" come from?

Thanks!

Aaron
169.XXX.XXX.XXX is a private address assigned by some OS when unable to
reach a DHCP server where one was expected. Your code may be calling for
a new address rather than finding the address of your computer.
 
A

Arved Sandstrom

Aaron Fude said:
Hi,

The result of calling

java.net.InetAddress.getLocalHost().getHostAddress()

on my machine is:

169.254.221.10

Now, my machine is on a LAN with IP 192.168.1.3 and the external
router IP is something altogether different.

Where in the world does "169.254.221.10" come from?

Thanks!

Aaron

Like Dave said, this is not a good address. For example, I'm on a router
too, and my IP address (using the Java code above) is 192.168.1.100.

If the PC goes out looking for an IP address, and for some reason can't
locate a DHCP server to give it one, it will self-assign using APIPA, from
the 169.254.x.x range.

Check your Ethernet cable first. Or both, depending on whether or not you
are wirelessly or cable-connected to your router. Change the cable if
necessary. Keep an eye on the PC light on the modem when you do it. Do some
ipconfig /release and /renew commands afterwards (or Repair on the network
connection). Do power cycles on the modem as necessary (like after a cable
swap). Turn off your firewall temporarily to see if that's the problem. Try
a direct connect between the modem and PC if necessary. Reinstall
TCP/IP....well, you get the drift, a 169.254.x.x can be a bastard.

Main thing is, check the cable connections first.

Arved
 
K

Kevin McMurtrie

RedGrittyBrick said:
A computer typically has many IP addresses.

Depending on o/s try "ipconfig -a" or "ifconfig /all" at the command prompt.

And "localhost" might even be "0:0:0:0:0:0:0:1%0".
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top