The previous poster pretty much said it all...
BUT...I'd be very wary about using using a script to automatically add the ip addresses of SPOOFED packets to ANY IP tables firewall.
Tools like nmap can generate thousands of spoofed connection requests per second.
In this case you could end up in some bad situations:
Your own ip gets spoofed, blocked and you can't access your own server anymore.
You block thousands of innocent ISP clients from accessing your system making the solution worse than the problem.
You add so many entries to iptables that your server slows to a crawl and iptables eats up so much memory your clients can't use your server (DOSing yourself!!)
If it is a SYN flood OCCURING FROM SPOOFED IP's simply turning on syn cookies is the safest defense. To do that:
Put following in /etc/sysctl.conf
this will enable it automatically on boots
#enable TCP SYN cookie protection
net.ipv4.tcp_syncookies=1
If the ip's ARE NOT SPOOFED then the firewall option is then a reasonable solution.
Also see this thread:
http://forum.ev1servers.net/showthread.php...&threadid=17363