java.net.InetAddress.getHostAddress()  IP地址java.net.InetAddress.getHostName()  机器名

解决方案 »

  1.   

    import java.net.*;public class IPAddressDemo
    {
        InetAddress localIPAddress = null;
        InetAddress ccidnetIPAddress = null;
        public  static void main( String args[])
        {
            IPAddressDemo  ipInstance;
            ipInstance = new IPAddressDemo();
            System.out.println("本机IP地址 : " +"\t"+ ipInstance.getLocalIP());
            System.out.println("点点通服务器IP地址 : " +
                               ipInstance.getCCIDNETIP("www.manhuabao.com"));
            System.out.println("点点通服务器域名 : " +
                               ipInstance.getCCIDNETName());
        }
        //取得本机IP地址成员方法
        public InetAddress getLocalIP()
        {
            try
            {
                localIPAddress = InetAddress.getLocalHost();
            }
            catch (UnknownHostException e){
            }
            return ( localIPAddress );
        }
        //取得点点通服务器的IP地址成员方法
        public InetAddress getCCIDNETIP( String strServerName )
        {
            try
            {
                ccidnetIPAddress = InetAddress.getByName( strServerName );
            }
            catch (UnknownHostException e){
            }
            return ( ccidnetIPAddress );
        }
        //通过IP地址封装对象取得计算机系统域名成员方法
        public String getCCIDNETName()
        {
            String strServerName = null;
            try
            {
                strServerName = ccidnetIPAddress.getHostName();
            }
            catch (SecurityException e){
            }
            return ( strServerName );
        }
    }