Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import all necessary packages and classes
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- public class DNSClient0 {
- public static void main(String[] args) {
- try {
- // get the IP address of the local host
- InetAddress inetAddress0 = InetAddress.getLocalHost();
- System.out.println("local host " + inetAddress0);
- // resolve the IP address of missouriwestern.edu
- InetAddress inetAddress1 = InetAddress.getByName("www.missouriwestern.edu");
- // print the host name for the resolved address
- System.out.println(inetAddress1.getHostName());
- // print the IP address in textual presentation
- System.out.println(inetAddress1.getHostAddress());
- // resolve all IP addresses of amazon.com
- InetAddress[] inetAddressArray0 = InetAddress.getAllByName("www.amazon.com");
- for(int i=0; i<inetAddressArray0.length; i++) {
- // print the host name for the resolved address
- System.out.println(inetAddressArray0[i].getHostName());
- // print each IP address mapped to amazon.com in textual presentation
- System.out.println(inetAddressArray0[i].getHostAddress());
- }
- } catch (UnknownHostException unknownHostException0) {
- System.out.println(unknownHostException0);
- }
- }
- }
Add Comment
Please, Sign In to add comment