//Java program to print IP address
//Java program to print domain name
//Java program using InetAddress class
//Java program to print domain name
//Java program using InetAddress class
Description
This program is used to print the IP address of a website or a system by using the domain name. The getByName() method is used to get the ip address of the specified domain name. Some sites inclue multiple IP addresses, the getAllByName() method is used to fetch all the IP addresses associated with a site.
Progarm
import java.net.*; public class IpClass { public static void main(String s[]) throws UnknownHostException { InetAddress add; add=InetAddress.getByName("programs-code.blogspot.com"); System.out.println("\n"); System.out.println(add); System.out.println("\n"); InetAddress address[]=InetAddress.getAllByName("programs-code.blogspot.com"); for(int i=0;i<address.length;i++) System.out.println(address[i]); } }
Output
Java IP address using InetAddress |
No comments:
Post a Comment