Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Italy
- web
- Software Engineering
- history
- Book review
- QT
- agile
- Programming
- RFID
- Malaysia
- Spain
- hbase
- programming_book
- management
- comic agile
- essay
- Book
- psychology
- Kuala Lumpur
- Python
- MySQL
- Java
- hadoop
- leadership
- Linux
- program
- France
- ubuntu
- erlang
- django
Archives
- Today
- Total
host name 얻기 본문
import java.net.InetAddress; import java.net.UnknownHostException; class GetHostName { public static void main(final String[] args) { // http://www.devx.com/tips/Tip/13284: try { java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); System.out.println("Hostname of local machine: " + localMachine.getHostName()); } catch (java.net.UnknownHostException uhe) { // [beware typo in code sample -dmw] // handle exception } // http://javaalmanac.com/egs/java.net/GetHostname.html: try { // Get hostname by textual representation of IP address InetAddress addr = InetAddress.getByName("127.0.0.1"); // [127.0.0.1 is always localhost -dmw]/ // Get hostname by a byte array containing the IP address byte[] ipAddr = new byte[]{127, 0, 0, 1}; addr = InetAddress.getByAddress(ipAddr); // Get the host name from the address String hostname = addr.getHostName(); // Get canonical host name String hostnameCanonical = addr.getCanonicalHostName(); } catch (UnknownHostException e) { // handle exception } } }
Comments