Convert Url to InetAddress

Simply call InetAddress.getByName(String host) passing in your textual IP address.

From the javadoc: The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address.

// print the IP Address of your machine (inside your local network)
		System.out.println(InetAddress.getLocalHost().getHostAddress());

		// print the IP Address of a web site
		System.out.println(InetAddress.getByName("www.javacodegeeks.com"));

		// print all the IP Addresses that are assigned to a certain domain
		InetAddress[] inetAddresses = InetAddress.getAllByName("www.google.com");

		for (InetAddress ipAddress : inetAddresses) {
			System.out.println(ipAddress);
		}


你可能感兴趣的:(Convert Url to InetAddress)