Java program to find the IP addresses of the following websites: Facebook , google , yahoo in the same try and catch -


here code 1 website need make multiple ip's in same try , catch

package javaapplication1;  import java.net.inetaddress; import java.net.unknownhostexception;  public class javaapplication1 {      public static void main(string[] args) {          try {             inetaddress[] addresses = inetaddress.getallbyname("google.com");              (inetaddress address : addresses) {                 system.out.println(address);               }         } catch (unknownhostexception ex) {             system.out.println("could not find");         }     } } 

make list of facebook,google , yahoo

iterate on list , use inetaddress.getallbyname(list.get(index))

arraylist<string> list = new arraylist<>();         list.add("facebook");// can add more urls         (string ip : list) {             try {                 inetaddress[] addresses = inetaddress.getallbyname(ip);                  (inetaddress address : addresses) {                     system.out.println(address);                  }             } catch (unknownhostexception ex) {                 system.out.println("could not find");             }         } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -