Question

In: Computer Science

Write a program to demonstrate the use of InetAddress. The program takes a list of names...

Write a program to demonstrate the use of InetAddress. The program takes a list of names or IP addresses as command line parameters and prints the name and an IP address of the local host, followed by names and IP addresses of the hosts specified on the command line. use java program

Solutions

Expert Solution

import java.net.*;

public class IPCharacteristics {

  public static void main(String[] args) {

    try {
      InetAddress address = InetAddress.getByName(args[0]);

      if (address.isAnyLocalAddress()) {
        System.out.println(address + " is a wildcard address.");
      }
      if (address.isLoopbackAddress()) {
        System.out.println(address + " is loopback address.");
      }

      if (address.isLinkLocalAddress()) {
        System.out.println(address + " is a link-local address.");
      } else if (address.isSiteLocalAddress()) {
        System.out.println(address + " is a site-local address.");
      } else {
        System.out.println(address + " is a global address.");
      }

      if (address.isMulticastAddress()) {
        if (address.isMCGlobal()) {
          System.out.println(address + " is a global multicast address.");
        } else if (address.isMCOrgLocal()) {
          System.out.println(address
           + " is an organization wide multicast address.");
        } else if (address.isMCSiteLocal()) {
          System.out.println(address + " is a site wide multicast
                             address.");
        } else if (address.isMCLinkLocal()) {
          System.out.println(address + " is a subnet wide multicast
                             address.");
        } else if (address.isMCNodeLocal()) {
          System.out.println(address
           + " is an interface-local multicast address.");
        } else {
          System.out.println(address + " is an unknown multicast
                             address type.");
        }
      } else {
        System.out.println(address + " is a unicast address.");
      }
    } catch (UnknownHostException ex) {
      System.err.println("Could not resolve " + args[0]);
    }
  }
}

Related Solutions

PART A Write a C program that takes the names and surnames of the students and...
PART A Write a C program that takes the names and surnames of the students and then displays the initial and last name of the name on the screen. For instance, if Onur Uslu is entered as input, the output of our program must be O. Uslu. PART B Write a C program that asks the user to enter a string and then sends it to a function that does the following job and shows the response from the function...
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
Write a program that uses Python List of strings to hold the five student names, a...
Write a program that uses Python List of strings to hold the five student names, a Python List of five characters to hold the five students’ letter grades, and a Python List of four floats to hold each student’s set of test scores. The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average....
Write a program to read in a list of domain names from the provided file (domains.dat),...
Write a program to read in a list of domain names from the provided file (domains.dat), and print the reverse domain names in sorted order. For example, the reverse domain of cs.princeton.edu is edu.princeton.cs. This computation is useful for web log analysis. To do so, create a data type Domain, using reverse domain name order. The H file contains the required functions. The compareTo function is provided for you. This will allow you to compare 2 Domain objects. Also use...
write a simple program to demonstrate the use of static type of variables in c++... use...
write a simple program to demonstrate the use of static type of variables in c++... use comments to explain plz
write a program using Java language that is- Implement Stack with a linked list, and demonstrate...
write a program using Java language that is- Implement Stack with a linked list, and demonstrate that it can solve the Tower of Hanoi problem. Write implementation body of method “infixToPrefix(String[] e)” of class ArithmeticExpression to convert infix expressions into prefix expressions.
Q1-      Write a program that takes a list of values as an input from the user....
Q1-      Write a program that takes a list of values as an input from the user. The program should further ask the user about sorting the list in ascending or descending order. It is desirable to use Arraylist/Vector in place of simple arrays. (Object Oriented Programming java)
Can you write a small program in c++ demonstrate the use of pointer (*) & (&)....
Can you write a small program in c++ demonstrate the use of pointer (*) & (&). Can you also explain the pointer system and how to use them. Thank you.
languague c++ Write a program to demonstrate the use of STACKS. The scenario is as follows:...
languague c++ Write a program to demonstrate the use of STACKS. The scenario is as follows: There is a MAZE. There is a mouse inside the maze. The mouse must find the exit from the maze. When the user clicks the letter C or c a CAT is added to the maze. The cat will run through the maze and if it finds the mouse it should eat it and the game is over! User can add as many cats...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT