Results 1 to 1 of 1
Thread: Looking Up the Address of a Host
-
Looking Up the Address of a Host
This Java tip shows how to look up the address of a host.
Java Code:import java.net.InetAddress; import java.net.UnknownHostException; public class DNSLookup { public static void main(String args[]) { try { InetAddress host; if (args.length == 0) { host = InetAddress.getLocalHost(); } else { host = InetAddress.getByName(args[0]); } System.out.println("Host:'" + host.getHostName() + "' has address: " + host.getHostAddress()); byte bytes[] = host.getAddress(); int fourBytes[] = new int[bytes.length]; for (int i = 0, n = bytes.length; i < n; i++) { fourBytes[i] = bytes[i] & 255; } System.out.println("\t" + fourBytes[0] + "." + fourBytes[1] + "." + fourBytes[2] + "." + fourBytes[3]); } catch (UnknownHostException e) { e.printStackTrace(); } } }
Similar Threads
-
Getting the host of the applet
By Java Tip in forum Java TipReplies: 0Last Post: 03-10-2008, 02:56 PM -
Getting the host from where the Applet was loaded
By Java Tip in forum Java TipReplies: 0Last Post: 02-15-2008, 08:41 AM -
JSP – getting IP address
By Java Tip in forum Java TipReplies: 0Last Post: 01-29-2008, 09:05 AM -
Getting host name/address
By Java Tip in forum Java TipReplies: 0Last Post: 11-19-2007, 04:34 PM -
Error with Sql 2000:java.net.NoRouteToHostException: No route to host: connect
By bbq in forum JDBCReplies: 0Last Post: 06-27-2007, 07:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks