回帖的时候自己都觉得不对,重新查了下JAVA网络编程:6.1.1.3 public static InetAddress getByAddress(byte[ ] address) throws UnknownHostException // Java 1.4public static InetAddress getByAddress(String hostName, byte[] address) throws UnknownHostException // Java 1.4 In Java 1.4 and later, you can pass a byte array and optionally a hostname to getByAddress() to create an InetAddress object with exactly those bytes. Domain name lookup is not performed. However, if byte array is some length other than 4 or 16 bytes—that is, if it can't be an IPv4 or IPv6 address—an UnknownHostException is thrown.This is useful if a domain name server is not available or might have inaccurate information. For example, none of the computers, printers, or routers in my basement area network are registered with any DNS server. Since I can never remember which addresses I've assigned to which systems, I wrote a simple program that attempts to connect to all 254 possible local addresses in turn to see which ones are active. (This only took me about 10 times as long as writing down all the addresses on a piece of paper.)getByAddress(byte[] address) really doesn't do anything getByAddress(String address) doesn't do. In a few cases, it might be marginally faster because it doesn't have to convert a string to a byte array, but that's a trivial improvement. getByAddress(String hostName, byte[] address) does let you create InetAddress objects that don't match or even actively conflict with the information in the local DNS. There might occasionally be a call for this, but the use case is pretty obscure. 以前都是用getByName("202.119.24.35"),但在JAVA1.4中不能显示主机名,而只能显示/202.119.24.35.
除非你自已有DNS服务,好像不能从IP得到域名
In Java 1.4 and later, you can pass a byte array and optionally a hostname to getByAddress() to create an InetAddress object with exactly those bytes. Domain name lookup is not performed. However, if byte array is some length other than 4 or 16 bytes—that is, if it can't be an IPv4 or IPv6 address—an UnknownHostException is thrown.This is useful if a domain name server is not available or might have inaccurate information. For example, none of the computers, printers, or routers in my basement area network are registered with any DNS server. Since I can never remember which addresses I've assigned to which systems, I wrote a simple program that attempts to connect to all 254 possible local addresses in turn to see which ones are active. (This only took me about 10 times as long as writing down all the addresses on a piece of paper.)getByAddress(byte[] address) really doesn't do anything getByAddress(String address) doesn't do. In a few cases, it might be marginally faster because it doesn't have to convert a string to a byte array, but that's a trivial improvement. getByAddress(String hostName, byte[] address) does let you create InetAddress objects that don't match or even actively conflict with the information in the local DNS. There might occasionally be a call for this, but the use case is pretty obscure.
以前都是用getByName("202.119.24.35"),但在JAVA1.4中不能显示主机名,而只能显示/202.119.24.35.
final InetAddress addr = InetAddress.getByAddress(b);
InetAddress addr = InetAddress.getByAddress(b);
System.out.println(arr.getHostName());