$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);
if($url['country']!="US") {
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";
}
?>
*/2 * * * * /usr/bin/php /root/ip_monitor.php >> /root/ip-results.txt 2>> /root/ip-errror.txt
No hay comentarios:
Publicar un comentario