Friday, May 11, 2012

Basic IP Check with Ping using Java



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;


public class testIp {

public static boolean checkIp (String sip)
  {
      String [] parts = sip.split ("\\.");
      System.out.println("Parts length is "+parts.length);
      if ( parts.length != 4 )
      {
          return false;
      }
      for (String s : parts)
      {
          int i = Integer.parseInt (s);
          if (i < 0 || i > 255)
          {
              return false;
          }
      }
      if (pingIp(sip))
      return true;
      else
      return false;
  }

private static boolean pingIp(String sip) {
// TODO Auto-generated method stub
try {
InetAddress adr = InetAddress.getByName(sip);
boolean stat= adr.isReachable(2000);
return stat;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return false;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Enter the IP to be chacked");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {

String line = br.readLine();
boolean status=testIp.checkIp(line);
System.out.println("Status is "+status);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}




Thursday, May 10, 2012

EMMA Report Comparison Shell Based Utility


Here i am pasting the Symbolic code for comparing two EMMA Reports where Assumptions are
1.before.txt ---> the actual report
2.after.txt----> report after modification

This Script will get in to those twpo reports and show block by Block Comparison
The idea behind sharing this is that using this Logic a Extensive User Utility script can be developed which can be used to compare EMMA Reports



function retLineNobefore()
{
Str=$1
while read Line
do
val=$(grep -n "$Str" | sed -n 's/^\([0-9]*\)[:].*/\1/p')   # this is to Extract just the Line no
break
done < before.txt
}

function retLineNoAfter()
{
Str=$1
while read Line
do
val=$(grep -n "$Str" | sed -n 's/^\([0-9]*\)[:].*/\1/p')
break
done < after.txt
}

rm -fr report.txt

retLineNobefore "OVERALL COVERAGE SUMMARY:"
no1=$val


retLineNobefore "OVERALL STATS SUMMARY:"
no2=$val
echo "----------------Before-------------------------- " > report.txt

awk "{if((NR>"$no1")&&(NR<$no2)) print}" before.txt  >> report.txt



retLineNoAfter "OVERALL COVERAGE SUMMARY:"
no1=$val
echo $no1


retLineNoAfter "OVERALL STATS SUMMARY:"
no2=$val
echo $no2
echo "----------------After-------------------------- " >> report.txt
awk "{if((NR>"$no1")&&(NR<$no2)) print}" after.txt  >> report.txt