See these functions of java.net.InetAddress - getLocalHost and getHostName :
String localhostname = java.net.InetAddress.getLocalHost().getHostName();
Note that this gets you the hostname as the machine sees itself; others may see it with a different one (e.g. the local hosts
file says something different than DNS). In other words, it is not guaranteed that machine A will be seen with the same hostname from machine A, machine B, or machine C.
As @biniam_Ethiopia points out, it is not even guaranteed that you'll get the same result from different programs on the same machine, as they may be using network-based name resolution (seen e.g. here).
It may be more useful to send the whole identifier: [email protected]
, instead of just piskvor
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…