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


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


    網站導航:
     
    主站蜘蛛池模板: 老司机午夜性生免费福利 | 2021国内精品久久久久精免费| 俄罗斯极品美女毛片免费播放| 亚洲综合精品成人| 无码av免费毛片一区二区| 亚洲图片在线观看| 中文字幕成人免费视频| 亚洲精品高清久久| 天天影院成人免费观看| 7777久久亚洲中文字幕蜜桃| 16女性下面无遮挡免费| 久久精品亚洲精品国产色婷| 亚洲w码欧洲s码免费| 亚洲国产精品成人综合久久久| 亚洲免费黄色网址| 亚洲免费网站观看视频| 日本免费网站在线观看| 香港经典a毛片免费观看看| 午夜国产羞羞视频免费网站| 特黄特色的大片观看免费视频| 亚洲人成人无码网www国产| 亚洲AV无码一区二三区| 一级毛片无遮挡免费全部| 在线A亚洲老鸭窝天堂| 国产免费AV片在线观看| 国产成人免费全部网站 | 亚洲av午夜精品一区二区三区| 香蕉97碰碰视频免费| 久久久久亚洲AV成人网人人网站| 国产一区二区三区免费观在线| 在线观看亚洲免费| 一级做a爰性色毛片免费| 国产成人无码综合亚洲日韩| 中文字幕免费视频| 亚洲av无码一区二区三区四区| 全黄a免费一级毛片人人爱| 日本在线免费播放| 91在线亚洲综合在线| 亚洲精品tv久久久久| 久久国产免费一区二区三区| 亚洲日韩看片无码电影|