#!/usr/bin/perl -w # Blocks incoming connections on port 25 from the specified IP (with iptables) # Usage: ./blockmailfromip aa.bb.cc.dd # Author: Juan R. Pozo - http://html.conclase.net/cp/scripts/ # Released on December 8, 2003 ############################################################################### # This software is released into the public domain. Use at your own risk. # The author holds no rights or responsibilities related to this software. ############################################################################### # iptables -A INPUT -s aa.bb.cc.dd -p tcp --destination-port 25 -j DROP ############################################################################### use strict; if (scalar @ARGV != 1 || $ARGV[0] !~ /^(\d{1,3}\.){3}\d{1,3}$/) { die("Usage: ./blockmailfromip aa.bb.cc.dd\n"); } my @check = `iptables -nL INPUT | grep $ARGV[0]`; # DROP tcp -- aa.bb.cc.dd 0.0.0.0/0 tcp dpt:25 foreach (@check) { if (/^DROP\s+tcp\s+--\s+$ARGV[0]\s+0.0.0.0\/0\s+tcp dpt:25/) { die("Mail coming from specified IP is already being blocked.\n"); } } print `iptables -A INPUT -s $ARGV[0] -p tcp --destination-port 25 -j DROP 2>&1`; print "Done\n"; print `iptables -nL INPUT | grep $ARGV[0]`; exit;