dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Nov 22, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Find an IP Address by Name

Find the IP address of a server that you know, for example: google.com.

Java, as usual, provides a very easy mechanism to retrieve the IP address of a server that you know.

import java.net.*;

public class FindIPByName {
    
   static String url = "google.com";
   public static void main(String[] args) {
      
      if (args.length == 1)
         url = args[0];
      try 
      {
         System.out.println(InetAddress.getByName(url));
      }catch(java.net.UnknownHostException uhe)
      {
         System.out.println("Unknown host: " + url);
      }
    }
}

/*

Expected output:

[root@mypc]# java FindIPByName 
google.com/216.58.220.46
[root@mypc]#
[root@mypc]# java FindIPByName Oracle.com
Oracle.com/137.254.120.50

*/
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date