🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #20335

Re: ����linux����λ�ñ������ʵip��

#20335
From: tHeCuRe
Date: Fri, 19 Dec 2003 01:11
45 lines
2627 bytes
   /**
     * Find and list all network interfaces and IP addresses bound to host m
achine
   */
    private void listHostIpAddress() {
        try {
            log.info("Finding network interfaces and IP addresses bound to e
                      ach network interface .....");
            Enumeration nifs= NetworkInterface.getNetworkInterfaces();
            while (nifs.hasMoreElements()) {
                NetworkInterface netIf= (NetworkInterface)nifs.nextElement();

                String nifName= netIf.getName();
                log.info("========================= Network Interface: " + n
                           ifName);
                for (Enumeration nifIp= netIf.getInetAddresses();
                     nifIp.hasMoreElements();) {
                    InetAddress address= (InetAddress)nifIp.nextElement();
                    String ip= address.getHostAddress();

                    //grab the first non-loopback address
                    //if(!ip.equals("127.0.0.1")) return ip;

                    log.info("     >>>>>>>>>> NIF " + nifName + ", IP = " + 
                                ip);
                }
            }
            log.info("Found all network interfaces and IP addresses for this
                      host ...........");
        } catch (Exception e) {
            log.error("Error when list network interfaces and IP addresses i
                       n listHostIpAddress of ComServerManager, ", e);
        }
    }

�� �� wakoo.bbs@Freecity.dhs.org (wakoo) �Ĵ������ᵽ: ��
: ��InetAddress.getLocalHost().getHostAddress();��õ���127.0.0.1
: �ǵ���ǰ��redhat��suse����û����ģ�������magic�Ͳ����ˣ��벻ͨ
: ����NetworkInterfaceŪ�˰��죬���Dz���


--

Life is life.
�� ��Դ:���Ұ��Ͽ�վ bbs.nankai.edu.cn��[FROM: 202.113.25.3] 
Technical Details
Message-ID: <49hLET$AOI@bbs.nankai.edu.cn>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsgate.cuhk.edu.hk!news.zixia.net!news.happynet.org!NanKai

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f6cb0,da215c7badbc1e68,start
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2003-12-18 17:14:02 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsgate.cuhk.edu.hk!news.zixia.net!news.happynet.org!NanKai
From: hoopdream.bbs@bbs.nankai.edu.cn (tHeCuRe)
Newsgroups: cn.bbs.comp.lang.java
Subject: Re: ����linux����λ�ñ������ʵip��
Date: 19 Dec 2003 01:11:39 GMT
Organization: �Ұ��Ͽ�վ
Message-ID: <49hLET$AOI@bbs.nankai.edu.cn>
X-Filename: Java/M.1071796157.A
Lines: 45