Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- if ( count($argv) < 3 ) {
- print "Argumento invalido: informe a porta e o numero maximo de conexoes permitidas\n";
- exit('Sintaxe de uso: ' . $argv[0] . ' <porta_a_ser_observada> <numero_maximo_de_conexoes>' . "\n");
- }
- $file = str_replace('.php', '.txt', __FILE__);
- @exec('/bin/netstat -nt | /bin/cut -d: -f2 | /bin/sort | /usr/bin/uniq -c | /bin/sort -n > ' . $file . ' 2>/dev/null');
- $lines = file($file, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
- foreach ($lines as $line) {
- $info = preg_split('#\s+#', $line);
- list($number, $port, $ip) = trim_empty_values($info);
- if ( !is_numeric($port) ) continue;
- if ( $port == $argv[1] ) {
- echo 'Ha ', $number, ' conexoes a porta ', $port, ' a partir do IP ', $ip, "\n";
- if ( $number >= $argv[2] ) {
- echo "O host $ip ultrapassou o limite de conexoes ($number)\n";
- if ( !in_array($ip, ['127.0.0.1', trim(`/bin/hostname --ip-address`)]) ) {
- # passthru('/usr/sbin/csf -d ' . $ip . ' "Ataque ao servidor" ');
- }
- }
- }
- }
- function trim_empty_values ($array) {
- foreach ( $array as $key => $value ) {
- if ( empty($value) ) unset($array[$key]);
- }
- return array_values($array);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement