private String getLocalSiteIP() throws Exception {
String siteString = "";
    Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
    while (netInterfaces.hasMoreElements()) {
      NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
      InetAddress ip = (InetAddress) ni.getInetAddresses().nextElement();
      if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() &&
          ip.getHostAddress().indexOf(":") == -1) {
        System.out.println("Interface " + ni.getName() +
                           " seems to be InternetInterface. I'll take it...");
        siteString = ip.getHostAddress();
      }
    }
    return siteString;
  }对单网卡有用,windows/linux都调通,希望对你有用,多网卡还是让用户配置吧