可以
InetAddress.getLocalHost()

解决方案 »

  1.   

    InetAddress address=InetAddress.getByName(getCodeBase().getHost());
    这样可以返回服务器的网络地址
    可以参考<think in java>网络编程15.5.2
      

  2.   

    import java.net.*;public class NetTool

    InetAddress myIPaddress=null; InetAddress myServer=null; public static void main( String args[])
    { NetTool mytool; mytool=new NetTool(); System.out.println("Your host IP is: " + mytool.getMyIP()); System.out.println("The Server IP is :" +mytool.getServerIP()); }file://取得LOCALHOST的IP地址 public InetAddress getMyIP() 
    { try 

    myIPaddress=InetAddress.getLocalHost();
    }  catch (UnknownHostException e) {} return (myIPaddress);
    } file://取得 www.abc.com 的IP地址 public InetAddress getServerIP()
    {  try 
    {
    myServer=InetAddress.getByName( "www.abc.com");
    } catch (UnknownHostException e) {}  return (myServer); 

      

  3.   

    学习了,我以前用第一个函数无论如何取都只是localhost与127.0.0.1