private String getBridgeAddress()
{
String osgiServer = "surenpi.com";
try
{
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while(interfaces.hasMoreElements())
{
NetworkInterface network = interfaces.nextElement();
if(network.isUp() && !network.isLoopback() && !network.isVirtual())
{
if(InetAddress.getByName(osgiServer).isReachable(network, 0, 2000))
{
Enumeration<InetAddress> inetAddrs = network.getInetAddresses();
while(inetAddrs.hasMoreElements())
{
InetAddress addr = inetAddrs.nextElement();
if(addr instanceof Inet4Address)
{
String hostAddr = addr.getHostAddress();
return hostAddr;
}
}
}
}
}
}
catch (SocketException e)
{
e.printStackTrace();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
[/codesyntax]
转载于:https://my.oschina.net/surenpi/blog/481893