<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 肚子疼 閱讀(1095) 評論(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包  回復  更多評論   


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


    網站導航:
     
    主站蜘蛛池模板: 国产成人+综合亚洲+天堂| 亚洲日本在线观看网址| jizz免费一区二区三区| 亚洲区日韩区无码区| 黄页网站在线观看免费| 亚洲AV无码不卡在线观看下载| 曰批免费视频播放在线看片二| 免费精品国产自产拍观看| 午夜亚洲国产精品福利| 亚洲欧洲日本在线| 东方aⅴ免费观看久久av| 亚洲欧洲日韩国产综合在线二区| 男人的天堂网免费网站| 亚洲黄色免费网址| 九九九精品成人免费视频| 亚洲AV日韩AV永久无码色欲| 免费不卡中文字幕在线| 美女被免费网站91色| 久久精品国产亚洲AV香蕉| 成人无码精品1区2区3区免费看 | 国产在线观看免费观看不卡| 亚洲精品影院久久久久久| 4虎永免费最新永久免费地址| 亚洲一本之道高清乱码| 日韩一区二区免费视频| 日亚毛片免费乱码不卡一区| 亚洲AV综合色区无码一区爱AV| 99在线观看精品免费99| 亚洲精品国产精品| 亚洲综合伊人久久综合| 亚洲人成免费电影| 国产亚洲人成在线影院| 亚洲av无码国产精品夜色午夜| 久久综合AV免费观看| caoporm超免费公开视频| 亚洲码在线中文在线观看| 免费一级国产生活片| 久久国产精品2020免费m3u8| 亚洲日本中文字幕天天更新| 亚洲真人日本在线| 国产免费久久精品99re丫y|