<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    zhaozhao

    常用鏈接

    統計

    鏈接

    最新評論

    用java得到本機所有的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("發送失敗,失敗原因=" + 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();
    ??? }
    ? }
    }

    作者Blog: http://blog.csdn.net/woowindice/

    posted on 2006-04-19 01:04 肚子疼 閱讀(1093) 評論(3)  編輯  收藏 所屬分類: java基礎

    評論

    # re: 用java得到本機所有的ip地址 2006-05-08 22:10 仍然

    猴子樣  回復  更多評論   

    # re: 用java得到本機所有的ip地址 2006-07-18 20:18 肚子疼

    誰啊?  回復  更多評論   

    # re: 用java得到本機所有的ip地址 2011-02-22 21:58 Photon

    差2個Jar包  回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产天堂亚洲国产碰碰| 亚洲福利在线观看| 国产精品亚洲AV三区| 三年片在线观看免费大全| 久久精品国产亚洲av日韩| 真人做A免费观看| 久久久亚洲欧洲日产国码aⅴ| 亚洲免费人成在线视频观看| 亚洲开心婷婷中文字幕| 三级毛片在线免费观看| 亚洲VA中文字幕无码毛片| 三年片在线观看免费观看大全动漫| 91精品国产免费久久国语蜜臀| 成年人性生活免费视频| 亚洲国产三级在线观看| 免费a级毛片无码a∨免费软件| 日本免费人成黄页在线观看视频| 亚洲中文无码mv| 免费乱码中文字幕网站| 久久性生大片免费观看性| 2020久久精品国产免费| 亚洲国产视频久久| 免费A级毛片在线播放不收费| 成人在线免费视频| 久久久久久a亚洲欧洲AV| 国产在线观看麻豆91精品免费 | 美女视频黄a视频全免费| 亚洲黄页网在线观看| 免费一级大黄特色大片| 99久久99这里只有免费的精品| 亚洲精品高清视频| 最近2019中文字幕免费看最新| 窝窝影视午夜看片免费| 亚洲网站免费观看| 国产免费人成在线视频| 国产v亚洲v天堂a无| 亚洲国产成人久久综合区| 中文字幕在线免费观看| 亚洲av色香蕉一区二区三区蜜桃| 超清首页国产亚洲丝袜| 男男黄GAY片免费网站WWW|