Application Security Testing: An Integral Part of DevOps

The Java.net package has an API that does the hard work of collecting all the details and returns the name. It’s easy with the code snippet listed below.

Pass the as an argument and the code will retrieve the if it is valid.

import java.net.*;

public class FindHostnameUsingIPAddress
{
   public static void main(String args[])
   {
      FindHostnameUsingIPAddress findHostnameUsingIPAddress = new FindHostnameUsingIPAddress();
      findHostnameUsingIPAddress.proceed(args[0]);
   }
   
   private void proceed(String ipAddr)
   {
      try
      {
         String hostname = InetAddress.getByName(ipAddr).getHostName();
         System.out.println("Hostname of " + ipAddr + " is " + hostname);
      }catch(Exception e)
      {
         System.out.println("Exception: "+e);
      }
   }
}

/*

Expected output:

[[email protected]]# java FindHostnameUsingIPAddress 137.254.120.50
Hostname of 137.254.120.50 is vp-ocoma-cms-adc.oracle.com

*/



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here