<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包  回復  更多評論   


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲成a人片在线播放| 精品国产无限资源免费观看| 男女交性永久免费视频播放| 亚洲中文字幕一二三四区苍井空 | 青青操在线免费观看| 2048亚洲精品国产| 国产一区二区三区免费观在线| 亚洲一级Av无码毛片久久精品| 一级黄色免费毛片| 亚洲伊人久久精品影院| 两个人看的www免费视频| 久久噜噜噜久久亚洲va久| 久久久久久久岛国免费播放 | 午夜精品射精入后重之免费观看 | 中文字幕天天躁日日躁狠狠躁免费| 亚洲尹人香蕉网在线视颅| 96免费精品视频在线观看| 亚洲一区在线视频| 免费无遮挡无码视频网站| 一级毛片大全免费播放下载 | 久久99热精品免费观看牛牛| 亚洲精品综合久久中文字幕| 欧美日韩国产免费一区二区三区| 久久人午夜亚洲精品无码区| 亚洲男女内射在线播放| 成人久久免费网站| 久久精品亚洲中文字幕无码麻豆| 久久电影网午夜鲁丝片免费| 色多多www视频在线观看免费| 亚洲爆乳无码一区二区三区| 99久久这里只精品国产免费| 男女超爽视频免费播放| 亚洲AV无码一区二区二三区软件 | 成人片黄网站色大片免费观看cn| 老司机亚洲精品影院无码 | 国产大片51精品免费观看| 中文字幕av免费专区| 亚洲一级毛片免费观看| 亚洲成av人片在线观看天堂无码| 中文字幕免费观看| 免费手机在线看片|