Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //I recommend you run this from the command line
- $bind_ip = "0.0.0.0"; //all interfaces
- $bind_port = "22"; //SSH port
- $server = stream_socket_server("tcp://" . $bind_ip . ":" . $bind_port, $errno, $errorMessage);
- if (!$server)
- {
- throw new UnexpectedValueException("Couldn't bind to socket: $errorMessage");
- }
- while (true)
- {
- $client = @stream_socket_accept($server);
- if ($client)
- {
- $re = explode(":", stream_socket_get_name($client, true));
- $ip = $re[0];
- $string = "iptables -A INPUT -s " . $ip . " -j DROP";
- echo $ip . " has been blocked!" . "\n";
- exec($string);
- fclose($client);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment