将本机机器名转换成ip地址:
InetAddress addr = InetAddress.getByName(null);
    // Alternatively, you can use 
    // the address or name:
    // InetAddress addr = 
    //    InetAddress.getByName("127.0.0.1");
    // InetAddress addr = 
    //    InetAddress.getByName("localhost");

解决方案 »

  1.   

    InetAddress addr = InetAddress.getByName("www.sina.com.cn");
    String hostName = addr.getHostName();
    byte ipAddress[]= addr.getAddress();
      

  2.   

    import java.io.*;
    import java.net.*;
    import java.text.*;
    import java.util.*;
    ……String s="计算机名";
            try{
              InetAddress ip=InetAddress.getByName(s);
              System.out.println(s+"=="+ip.toString()+" host name="+ip.getHostName()+" path name="+ip.getHostName());
             
            }catch(Exception e){System.out.println(s+" is Á¬½Ó²»ÉÏ");}