Enumeration netInterfaces=NetworkInterface.getNetworkInterfaces();
    InetAddress ip=null;
    while(netInterfaces.hasMoreElements()){
      NetworkInterface ni=(NetworkInterface)netInterfaces.nextElement();
      System.out.println(ni.getName());
      ip=(InetAddress)ni.getInetAddresses().nextElement();
      if(!ip.isSiteLocalAddress()
 &&!ip.isLoopbackAddress()
 &&ip.getHostAddress().indexOf(":")==-1){
System.out.println("本机的ip="+ip.getHostAddress());
break;
      }
      else{
ip=null;
      }
    }
以上方法取得WEB服务器IP在window下正常,但是在redhatlinux as4下,执行发现取出的是IPV6格式的地址(inet6 addr: fe80::2e0:4cff:fe89:5286/64),而不是IPV4(inet addr:192.168.0.215).想问一下是否能实现他们之间的互相转换?先谢谢了!网卡信息如下:
eth0      Link encap:Ethernet  HWaddr 00:E0:4C:89:52:86  
          inet addr:192.168.0.215  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::2e0:4cff:fe89:5286/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2192 errors:0 dropped:0 overruns:0 frame:0
          TX packets:513 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:264699 (258.4 KiB)  TX bytes:137363 (134.1 KiB)
          Interrupt:169 Base address:0xa000