getHostAddress() liefert falsche IP

Status
Nicht offen für weitere Antworten.

Paulchen

Mitglied
Hallo freunde der kaffeetasse ;)

habe meinen Server von Windoof auf linux umgestellt und nun einige probleme beim anzeigen der IP Adresse auf dem Webserver (tomcat / JSP).

Source:

java.net.InetAddress myPC = java.net.InetAddress.getLocalHost();
String Computername = myPC.getHostName().toUpperCase();
String ipadresse = myPC.getHostAddress();


Das alte Windows system hatte meine IP erkannt ( 192.168.x.x)...
beim jetzigem linux kommt immer die IP vom LOCALHOST raus: 127.0.0.1

Wie kann ich das jetzt ändern dass ich nur die IP vom LAN auslese ?
Warum gibt es hier Unterschiede zwischen windows und linux.... java is ja sooo unabhängig ;)

mfg
Paule
 

Kerberus

Bekanntes Mitglied
Also bei mir reicht schon dieser Code aus: (vielleicht liegt es daran, dass ich mit MacOSX arbeite)
String host = InetAddress.getLocalHost().toString(); // dann musst du den String noch mit einem Tokenizer zersplitten
 

Bleiglanz

Gesperrter Benutzer
schau halt mal in die API und schau in /etc/hosts und schau, ob du lokal einen DNS Server hast usw.

ggf. mal java.net.NetworkInterface


Host name-to-IP address resolution is accomplished through the use of a combination of local machine configuration information and network naming services such as the Domain Name System (DNS) and Network Information Service(NIS). The particular naming services(s) being used is by default the local machine configured one. For any host name, its corresponding IP address is returned.

Reverse name resolution means that for any IP address, the host associated with the IP address is returned.

The InetAddress class provides methods to resolve host names to their IP addresses and vise versa. isLoopbackAddress()
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben