Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

jueves, 10 de noviembre de 2016

IP monitor

#!/usr/bin/php -q

<?php

$sip_peers=shell_exec("/usr/sbin/asterisk -x \" sip show peers\" | awk '{print $2}' | grep -v Unspecified | grep -v sip | grep -v Host");

$ip=explode("\n",$sip_peers);

foreach($ip as $key=>$value){

$url=file_get_contents("http://ipinfo.io/$value");

$url=json_decode($url, true);

$whitelist=array("71.41.210.190","66.241.99.90","64.2.142.187","104.238.138.237","127.0.0.1");

/* if($url['country']!="US");  use this if statement if want to filter by IP*/

if(!in_array($url['ip'],$whitelist)) {

if(!isset($url['ip'])) {
echo " too many request sent";
exit();
}

echo  $url['country']." RED ALERT  UNKNOWN IP ". $url['ip']."\n";

$body="Unauthorized peer   with the IP ". $url['ip'];

$headers = 'From: Asterisk Dominicana <ambiorixg12@asterisk-dominicana.com>' . "\r\n";

$headers  .= 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail("ambiorixg12@gmail.com"," Asterisk  Alert",$body,$headers);

$remoteip=$url['ip'];
system("/sbin/iptables -A INPUT -s $remoteip -j DROP");

continue;
}
echo $url['ip']." ".$url['country']."\n";

}





crontab -e
*/5 * * * * /usr/bin/php /root/ip_monitor.php >> /root/ip-results.txt 2>> /root/ip-errror.txt

No hay comentarios:

Publicar un comentario