Location: PHPKode > projects > Snort Log Monitor and Ticketing System > snortlogmonitor/myfunctions.php
<?

function IntToIPaddress($intValue)
{

  $strBinaryValue=decbin($intValue);
  $strBinaryValue=str_pad($strBinaryValue, 32, "0", STR_PAD_LEFT);

  if(strlen($strBinaryValue)==32)
  {
    $strBinaryOctet1=substr($strBinaryValue, 0, 8);
    $strBinaryOctet2=substr($strBinaryValue, 8, 8);
    $strBinaryOctet3=substr($strBinaryValue, 16, 8);
    $strBinaryOctet4=substr($strBinaryValue, 24, 8);

    $Octet1=bindec($strBinaryOctet1);
    $Octet2=bindec($strBinaryOctet2);
    $Octet3=bindec($strBinaryOctet3);
    $Octet4=bindec($strBinaryOctet4);

    $IPaddress=$Octet1.'.'.$Octet2.'.'.$Octet3.'.'.$Octet4;
  } else {
    $IPaddress=$intValue;
  }
  return($IPaddress);
}

function IPaddressToInt($IPaddressValue)
{

  ereg("([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)", $IPaddressValue, $matches);

  $I1=0+$matches[1];
  $I2=0+$matches[2];
  $I3=0+$matches[3];
  $I4=0+$matches[4];

  $strBin1=str_pad(decbin($I1),8,"0",STR_PAD_LEFT);
  $strBin2=str_pad(decbin($I2),8,"0",STR_PAD_LEFT);
  $strBin3=str_pad(decbin($I3),8,"0",STR_PAD_LEFT);
  $strBin4=str_pad(decbin($I4),8,"0",STR_PAD_LEFT);

  /* Or you could use this method
      $Str=sprintf("%08d",decbin($I3));  */

  $strBinaryNum=$strBin1.$strBin2.$strBin3.$strBin4;
  $decIPaddress=0 + bindec($strBinaryNum);
  return($decIPaddress);
}

?>
Return current item: Snort Log Monitor and Ticketing System