提交 ac3337f4 编写于 作者: C chao.liuc

DUBBO-76 增加通过host 获取ip的方法

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@346 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 099b1b77
......@@ -20,6 +20,7 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Random;
......@@ -204,8 +205,20 @@ public class NetUtils {
// ignore
}
return address;
}
}
/**
* @param hostName
* @return ip address or hostName if UnknownHostException
*/
public static String getIpByHost(String hostName) {
try{
return InetAddress.getByName(hostName).getHostAddress();
}catch (UnknownHostException e) {
return hostName;
}
}
public static String toAddressString(InetSocketAddress address) {
return address.getAddress().getHostAddress() + ":" + address.getPort();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册