小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

用java得到本機(jī)所有的ip地址

 pablo3518 2007-07-20
轉(zhuǎn)載聲明:版權(quán)規(guī)文章原創(chuàng)作者所有
轉(zhuǎn)載時(shí)間:2007年07月17日
轉(zhuǎn)載作者:pablo3518

用java得到本機(jī)所有的ip地址
 
package com.sourceware.util;

import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HttpClient;
import org.apache.log4j.Logger;
import java.net.InetAddress;
import java.util.Enumeration;
import java.net.NetworkInterface;
import java.util.*;

/**
 *
 * <p>Title: Sourceware utils.</p>
 *
 * <p>Description: Sourceware utils.</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: Sourceware inc.</p>
 *
 * @author 黑山(woowind@sina.com)
 * @version 1.0
 */
public class NetUtil {

  static Logger logger = Logger.getLogger(NetUtil.class);

  public NetUtil() {
  }

  /**
   *
   * @param url String
   * @return int
   * @throws Exception
   */
  public static int clickURL(String url) throws Exception {
    int retrycount = 3;
    while (true) {
      HttpClient httpClient = new HttpClient();
      GetMethod get = new GetMethod(url);
      get.addRequestHeader("Content-Type", "text/html; charset=GBK");
      int code = httpClient.executeMethod(get);
      if (code != 200) {
        if (retrycount == 0) {
          throw new Exception("發(fā)送失敗,失敗原因=" + code);
        }
        logger.error("send to[" + url + "]error code[" + code + "]");
        retrycount--;
      }
      else {
        return code;
      }

    } //end while(true)...
  }

  /**
   *
   * @return Collection
   */
  public static Collection getAllLocalIP() throws Exception {
    ArrayList ar = new ArrayList();
    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..."); ;
      }
      else {
        ar.add(ip.getHostAddress());
      }
    }
    return ar;
  }

  public static void main(String[] args) {
    try {
      NetUtil.getAllLocalIP();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀(guān)點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多