Dear all,
I have been struggling to find the "description" of the computer on which my Java application is running.
What I'm after is the name used for DNS when advertising my computer on the local network ("iMac Mattijs" in the screen shots below).
On Windows XP, this name can be found here: Control Panel -> System -> Computer Name -> Computer Description.
On Mac OS 10.6, this name can be found here: System Preferences -> Sharing -> Computer Name
The methods below don't deliver the name I'm looking for. Have a look at this code:
System.out.println("COMPUTERNAME environment variable: " + System.getenv("COMPUTERNAME"));
try { System.out.println("localhost name: " + InetAddress.getLocalHost().getHostName()); }
catch (UnknownHostException e1) {}
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface thisInterface = interfaces.nextElement();
Enumeration<InetAddress> addresses = thisInterface.getInetAddresses();
System.out.println("* network interface: " + thisInterface.getDisplayName());
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
System.out.println(" - address: " + address.getCanonicalHostName());
}
}
} catch (SocketException e) {}
On Windows, this prints:
COMPUTERNAME environment variable: ARTTECH-51CA5F5
localhost name: arttech-51ca5f5
* network interface: MS TCP Loopback interface
- address: localhost
* network interface: NVIDIA nForce Networking Controller - Packet Scheduler Miniport
* network interface: Broadcom 802.11n Network Adapter - Packet Scheduler Miniport
- address: arttech-51ca5f5.lan
* network interface: Bluetooth Device (Personal Area Network)
On Mac, I get:
COMPUTERNAME environment variable: null
localhost name: imac-mattijs.lan
* network interface: en1
- address: imac-mattijs.lan
- address: imac-mattijs.local
* network interface: lo0
- address: localhost
- address: fe80:0:0:0:0:0:0:1%1
- address: localhost
But I am looking for the full String "iMac Mattijs".
Any clues would be very welcome!
Thanks, Mattijs