Last active
December 17, 2015 07:49
-
-
Save roufiq/5575996 to your computer and use it in GitHub Desktop.
Source code untuk mendapatkan nama komputer yang sedang diakses dengan menggunakan Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.InetAddress; | |
import java.net.UnknownHostException; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author roufiq | |
*/ | |
public class ComputerName | |
{ | |
public static void main(String[] args) | |
{ | |
String hostname = "Unknown"; | |
try | |
{ | |
InetAddress addr; | |
addr = InetAddress.getLocalHost(); | |
hostname = addr.getHostName(); | |
} catch (UnknownHostException ex) { | |
Logger.getLogger(ComputerName.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
System.out.println("nama comp "+hostname); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment