将本机机器名转换成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");
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");
解决方案 »
- JEditorPane如何显示大文件(>100mb)
- BitSet的索引是什么概念
- java中,读取数据后怎么输出为表格,还有排序的?
- String s="a"+"b"+"c"; == StringBuffer sb = new StringBuffer().append("a").append("b").append("c")?????
- 散分!居然在 codeproject 上面发现自己的文章
- 急!!!!!!!请问cloudscape的问题!
- 关于回调函数 accept??
- 如何把String数组的元素联结为一个字符串?
- 请问如何把StringBuffer 的对象转化成一个InputStream 的对象,或者InputStream 子类的对象也可以!
- 急:请问高手:关于weblogic的问题
- Jbuild5.0中,如何设置类路径;
- 谢谢大家,请问如何把计算机名或服务器名转换成IP地址?
String hostName = addr.getHostName();
byte ipAddress[]= addr.getAddress();
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 Á¬½Ó²»ÉÏ");}