Linked Questions
26 questions linked to/from Recommended way to get hostname in Java
0 votes
1 answer
459 views
Getting local host name [duplicate]
When I try to get the hostname of my machine from the code, I'm using the following: address = InetAddress.getLocalHost().getCanonicalHostName(); The above throws an excpetion (UnknownHostException) ...
0 votes
0 answers
72 views
Is Windows 7 Bug Preventing Java getHostName() from Retrieving the Computer Name? [duplicate]
Our lab uses several ruggedized military laptops in a closed-network business environment. These computers are running identical Windows 7 versions, networked with static IP's, running Apache Tomcat ...
0 votes
0 answers
57 views
How to find out your computer name with Java [duplicate]
So I have this program and I would want to have Java figure out the username by itself. import java.io.*; import java.nio.file.Files; public class Demo { public static void main(String[] args) ...
180 votes
4 answers
217k views
Java current machine name and logged in user?
Is it possible to get the name of the currently logged in user (Windows/Unix) and the hostname of the machine? I assume it's just a property of some static environment class. I've found this for the ...
69 votes
3 answers
154k views
Getting the computer name in Java [duplicate]
I was wondering if there is a way to get the computer name in Java? I have seen several answers that feature java.net.InetAddress. However I was wondering if there is a way that does not use the ...
30 votes
4 answers
88k views
Get DNS name of local machine as seen by a remote machine
I'm making a peer-to-peer instant messaging application. Currently, if UserA.pool.net says "hello" to UserB.pool.net, User A sees "You: hello" and User B sees "UserA.pool.net: hello". Rather than ...
28 votes
5 answers
42k views
Find physical machine name in Java
How can I obtain the physical machine name that my jvm is running in? (Physical = OS, up to vmware...) Added from poster's comment: I mean the name of the computer the JVM is running in. Most likely ...
24 votes
9 answers
20k views
In Java 8, how do I get my hostname without hard-coding it in my environment?
We just upgraded to Java 8 on Amazon Linux. We are using Spring 4.3.8.RELEASE. It used to be that we could get our machine hostname by setting up beans in our application context file like so ... &...
6 votes
2 answers
4k views
Java getHostAddress() Returning VirtualBox IPv4 Address
I am using Java to build a simple method within a class that will grab the LAN IPv4 address of the user's machine. For the most part this works well, with one exception... the IP address I get back is ...
2 votes
1 answer
8k views
Control the hostname of the POD deployed via Kubernetes
I am trying to deploy my application using helm charts. I have defined a statefulSet as a kind under deployment.yaml and provided a headless service under spec.serviceName. Code snippet from ...
2 votes
3 answers
10k views
InetAddress.getLocalHost().getHostName() throws UnknownHostException
I am trying to get the host name off the server where it is running. Java code: import java.net.InetAddress; System.out.println("Host Name: " + InetAddress.getLocalHost().getHostName()); System....
2 votes
3 answers
5k views
System.getenv("computername") truncating return value
What is the difference between System.getenv("computername") and System.getenv("hostname") in Java? Is there any character limit on the computer name when retrieving it using the getenv() method? I ...
0 votes
1 answer
10k views
Fortify issue - Command Injection
I am trying to do hp fortify security scan for my java application. I have few issues and i have fixed it. But i am unable to find the fix for the below issue. Command Injection String hostname = ...
1 vote
4 answers
2k views
Bukkit.getIp() in player.sendMessage - Possible solution?
I'm making a plugin for my staff that can help them with some basic information. I'm trying to add a /ip for the server that will show the server ip, instead of the dns that they connect to. I'm ...
1 vote
2 answers
5k views
which is better between getting hostname using InetAddress or System.getenv
I posted a question about a problem that concerns inetaddress in java 8 : InetAddress java 8 is not getting the hostname however I found a simple solution by using System.getenv("HOSTNAME") instead ...