0% found this document useful (0 votes)
30 views3 pages

Expnet

This document contains 3 Java programs that use InetAddress to get IP addresses and host names from local and remote hosts. Program 1 gets the local host IP and name. Program 2 gets the IP and name for a specific host and the first command line argument. Program 3 compares the IP of the local host to a named host to check for equality.

Uploaded by

Sri Ram
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Expnet

This document contains 3 Java programs that use InetAddress to get IP addresses and host names from local and remote hosts. Program 1 gets the local host IP and name. Program 2 gets the IP and name for a specific host and the first command line argument. Program 3 compares the IP of the local host to a named host to check for equality.

Uploaded by

Sri Ram
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program - 1: import java.net.*; class ex1 { public static void main(String args[]) { try { InetAddress in= InetAddress.getLocalHost(); System.out.

println("Ip Address: "+in.getHostAddress()); System.out.println("Host Name: "+in.getHostName()); } catch(Exception e) { System.out.println("Ip address not found"); } } }

Output:

Program - 2: import java.net.*; class ex2 { public static void main(String args[]) { try { InetAddress in1= InetAddress.getByName("10.18.1.53"); InetAddress in2= InetAddress.getByName(args[0]); System.out.println("Ip Address: "+in1.getHostAddress()); System.out.println("Host Name: "+in2.getHostName()); } catch(Exception e) { System.out.println("Ip address not found"); } } }

Output:

Program - 3: import java.net.*; class ex3 { public static void main(String args[]) { try { InetAddress in1= InetAddress.getByName("CCC-35"); InetAddress in2= InetAddress.getLocalHost(); String s1=in1.getHostAddress(); String s2=in2.getHostAddress(); if(s1.equals(s2)) System.out.println("Ip Addresses equal"); else System.out.println("Not equal"); } catch(Exception e) { System.out.println("Ip address not found"); } } } Output:

You might also like