Guest User

Untitled

a guest
Nov 15th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public static String getHostNameForLiunx() {
  2. try {
  3. return (InetAddress.getLocalHost()).getHostName();
  4. } catch (UnknownHostException uhe) {
  5. String host = uhe.getMessage(); // host = "hostname: hostname"
  6. if (host != null) {
  7. int colon = host.indexOf(':');
  8. if (colon > 0) {
  9. return host.substring(0, colon);
  10. }
  11. }
  12. return "UnknownHost";
  13. }
  14. }
  15.  
  16. public static String getHostName() {
  17. if (System.getenv("COMPUTERNAME") != null) {
  18. return System.getenv("COMPUTERNAME");
  19. } else {
  20. return getHostNameForLiunx();
  21. }
Add Comment
Please, Sign In to add comment