能不能用这个: InetAddress localHost = InetAddress.getByName("hostname");
不过要知道servername

解决方案 »

  1.   

    试试把/etc/hosts文件里的
    127.0.0.1               xxxx localhost.localdomain localhost
    改为
    192.168.0.235           xxxx localhost.localdomain localhost
      

  2.   

    String hostName=InetAddress.getLocalHost().getHostName();
    String hostip=InetAddress.getByName(hostName).getHostAddress();btw,据我所知,InetAddress.getByName()这个函数基本上都是调用操作系统自身的getByName()(具体api名字忘记了),而系统的这个函数恰恰是先搜索host.conf这个文件里,是否有对应的
    ip<->hostName pair,如果有,就直接用这个文件里面的数据,如果没有,那么就建立socket连接去取.楼主可以作个试验.
      

  3.   

    java.net.InetAddress a = java.net.InetAddress.getLocalHost();
          System.out.print(a.getHostAddress());
      

  4.   


    我在windows2000平台下试过  禁用网卡后重新编译 并运行 得到127.0.0.1
                                启用网卡重新编译  运行  得到 局域网ip 192.155.0.23
      

  5.   

    对,修改host文件里的本地映射看看。把127.0.0.1的本地地址改成你本地的网络IP地址。
      

  6.   

    java.net.InetAddress a = java.net.InetAddress.getLocalHost();
    System.out.print(a.getHostAddress());
      

  7.   

    ipconfig >a.txtparse a.txtIP Address ........:192.168.3.1
     parse this line
      

  8.   

    linux:
    ifconfig  >a.txtparse a.txtIP Address ........:192.168.3.1
     parse this line
      

  9.   

    java不是说与平台无关吗???? 可恶.....