<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 肚子疼 閱讀(1094) 評論(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无码国产精品色午友在线| 亚洲六月丁香婷婷综合| 亚洲成aⅴ人片久青草影院按摩| 亚欧日韩毛片在线看免费网站| 亚洲av无码成h人动漫无遮挡| 99在线视频免费观看| 大学生高清一级毛片免费| 亚洲精品永久www忘忧草| 2020久久精品国产免费| 亚洲αv在线精品糸列| 你懂得的在线观看免费视频| 国产成人亚洲综合无码精品| 日本免费高清视频| 亚洲精品国产肉丝袜久久| 精品久久8x国产免费观看| 国产亚洲精aa在线看| 免费国产综合视频在线看 | 亚洲日韩一区二区三区| 国产成年无码久久久免费| 亚洲AV第一页国产精品| 麻豆91免费视频| 精品久久久久成人码免费动漫| 亚洲一级视频在线观看| 午夜高清免费在线观看| 免费夜色污私人影院网站电影| 免费毛片在线视频| 丰满妇女做a级毛片免费观看| 免费日本黄色网址| 韩日电影在线播放免费版| 亚洲精品电影在线| 亚洲AV无码成人精品区大在线| 亚洲免费网站观看视频| 国产精品亚洲产品一区二区三区 | 免费国产成人高清在线观看网站| 亚洲日产乱码一二三区别| 亚洲人成国产精品无码| 91成人免费在线视频| 在线观看国产一区亚洲bd| 国产成人精品免费视| 在线亚洲v日韩v| 亚洲毛片在线观看|