skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Sunday, October 14, 2012

Remote Host Ping Utility

Posted by Raju Gupta at 2:00 PM – 0 comments
 
This Program will display the target remote host name, target remote host address, canonical name and the local host name and IP address. This program will display the details of the target host which are behind the firewall with the help of proxy server. The following is a typical output of this program.

**************OUTPUT****************** 
Target Host Name :ABC.COM 
Target IP Address :111.77.222.100 
Target Host Canonical Name :DEF.SUN.com 
Local Host Name/IP Address :21386DGG2382/123.222.95.112 
**************************************  
 

import java.net.InetAddress;

public class HostPingSpecifications {
 public static void main(String args[]) throws Exception{
  String tagetHost = null;
  String socksProxyHost = null;
  String socksProxyPort = null;

  if(args.length > 2){
   socksProxyHost = args[0];
   socksProxyPort = args[1];
   tagetHost = args[2];
  }else if(args.length > 1){
   socksProxyHost = args[0];
   socksProxyPort = "80";
   tagetHost = args[1];
  }else if(args.length > 0){
   tagetHost = args[0];
  }
  else{
   System.out.println("**************ERROR******************");
   System.out.println("Error:Usage :");
   System.out.println("HostPingSpecifications  socksProxyHost socksProxyPort tagetHost");
   System.out.println("Or");
   System.out.println("HostPingSpecifications socksProxyHost tagetHost");
   System.out.println("Or");
   System.out.println("HostPingSpecifications tagetHost");
   System.out.println("*************************************");
   System.exit(1);
  }
  try{
   if(null != socksProxyHost){
    System.setProperty("socksProxyHost", socksProxyHost);
   }
   if(null != socksProxyPort){
    System.setProperty("socksProxyPort", socksProxyPort);
   }
   if(null != tagetHost){
   InetAddress ip = InetAddress.getByName(tagetHost);
   if(null != ip){
    System.out.println("**************OUTPUT******************");
    System.out.println("Target Host Name   :" + ip.getHostName());
    System.out.println("Target IP Address   :" + ip.getHostAddress());
    System.out.println("Target Host Canonical Name  :" + ip.getCanonicalHostName());
    System.out.println("Local Host Name/IP Address  :" + ip.getLocalHost());
    System.out.println("**************************************");
   }else{
    System.out.println("System returns unknown value null for the target host");
   }
   }else{
    System.out.println("System cannot accept null values for the target host. Please try again.");
   }
  }catch(Exception ex){
   System.out.println("Unknown Error Occurred");
   ex.printStackTrace();
  }
 }
}


Labels: Remote Host Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger