//package com.nowjava;
/*
来自
*N o w J a v a . c o m*/
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Main {
public static void main(String[] argv) throws Exception {
System.out.println(getHostName());
}
public static String getHostName() {
String server = null;
/** N o w J a v a . c o m 提 供 **/
// Obtain server name of local host
try {
final InetAddress localMachine = InetAddress.getLocalHost();
server = localMachine.getHostName();
} catch (final UnknownHostException e) {
server = "Unknown";
}
return server;
}
public static String getHostName(String ipAddress) {
String server = null;
try {
// Get hostname by textual representation of IP address
final InetAddress addr = InetAddress.getByName(ipAddress);
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。