Debian Codegraph @

ip-addresses.sh

raw symbols SCIP
1 #!/bin/bash
2 # ip-addresses.sh
3 # List the IP addresses your computer is connected to.
4
5 # Inspired by Greg Bledsoe's ddos.sh script,
6 # Linux Journal, 09 March 2011.
7 # URL:
8 # http://www.linuxjournal.com/content/back-dead-simple-bash-complex-ddos
9 # Greg licensed his script under the GPL2,
10 #+ and as a derivative, this script is likewise GPL2.
11
12 connection_type=TCP # Also try UDP.
13 field=2 # Which field of the output we're interested in.
14 no_match=LISTEN # Filter out records containing this. Why?
15 lsof_args=-ni # -i lists Internet-associated files.
16 # -n preserves numerical IP addresses.
17 # What happens without the -n option? Try it.
18 router="[0-9][0-9][0-9][0-9][0-9]->"
19 # Delete the router info.
20
21 lsof "$lsof_args" | grep $connection_type | grep -v "$no_match" |
22 awk '{print $9}' | cut -d : -f $field | sort | uniq |
23 sed s/"^$router"//
24
25 # Bledsoe's script assigns the output of a filtered IP list,
26 # (similar to lines 19-22, above) to a variable.
27 # He checks for multiple connections to a single IP address,
28 # then uses:
29 #
30 # iptables -I INPUT -s $ip -p tcp -j REJECT --reject-with tcp-reset
31 #
32 # ... within a 60-second delay loop to bounce packets from DDOS attacks.
33
34
35 # Exercise:
36 # --------
37 # Use the 'iptables' command to extend this script
38 #+ to reject connection attempts from well-known spammer IP domains.