Debian Codegraph @

is-spammer.sh

raw symbols SCIP
1 #! /bin/bash
2 # is-spammer.sh: Identifying spam domains
3
4 # $Id: is-spammer, v 1.4 2004/09/01 19:37:52 mszick Exp $
5 # Above line is RCS ID info.
6 #
7 # This is a simplified version of the "is_spammer.bash
8 #+ script in the Contributed Scripts appendix.
9
10 # is-spammer <domain.name>
11
12 # Uses an external program: 'dig'
13 # Tested with version: 9.2.4rc5
14
15 # Uses functions.
16 # Uses IFS to parse strings by assignment into arrays.
17 # And even does something useful: checks e-mail blacklists.
18
19 # Use the domain.name(s) from the text body:
20 # http://www.good_stuff.spammer.biz/just_ignore_everything_else
21 # ^^^^^^^^^^^
22 # Or the domain.name(s) from any e-mail address:
23 # [email protected]
24 #
25 # as the only argument to this script.
26 #(PS: have your Inet connection running)
27 #
28 # So, to invoke this script in the above two instances:
29 # is-spammer.sh spammer.biz
30
31
32 # Whitespace == :Space:Tab:Line Feed:Carriage Return:
33 WSP_IFS=$'\x20'$'\x09'$'\x0A'$'\x0D'
34
35 # No Whitespace == Line Feed:Carriage Return
36 No_WSP=$'\x0A'$'\x0D'
37
38 # Field separator for dotted decimal ip addresses
39 ADR_IFS=${No_WSP}'.'
40
41 # Get the dns text resource record.
42 # get_txt <error_code> <list_query>
43 get_txt() {
44
45 # Parse $1 by assignment at the dots.
46 local -a dns
47 IFS=$ADR_IFS
48 dns=( $1 )
49 IFS=$WSP_IFS
50 if [ "${dns[0]}" == '127' ]
51 then
52 # See if there is a reason.
53 echo $(dig +short $2 -t txt)
54 fi
55 }
56
57 # Get the dns address resource record.
58 # chk_adr <rev_dns> <list_server>
59 chk_adr() {
60 local reply
61 local server
62 local reason
63
64 server=${1}${2}
65 reply=$( dig +short ${server} )
66
67 # If reply might be an error code . . .
68 if [ ${#reply} -gt 6 ]
69 then
70 reason=$(get_txt ${reply} ${server} )
71 reason=${reason:-${reply}}
72 fi
73 echo ${reason:-' not blacklisted.'}
74 }
75
76 # Need to get the IP address from the name.
77 echo 'Get address of: '$1
78 ip_adr=$(dig +short $1)
79 dns_reply=${ip_adr:-' no answer '}
80 echo ' Found address: '${dns_reply}
81
82 # A valid reply is at least 4 digits plus 3 dots.
83 if [ ${#ip_adr} -gt 6 ]
84 then
85 echo
86 declare query
87
88 # Parse by assignment at the dots.
89 declare -a dns
90 IFS=$ADR_IFS
91 dns=( ${ip_adr} )
92 IFS=$WSP_IFS
93
94 # Reorder octets into dns query order.
95 rev_dns="${dns[3]}"'.'"${dns[2]}"'.'"${dns[1]}"'.'"${dns[0]}"'.'
96
97 # See: http://www.spamhaus.org (Conservative, well maintained)
98 echo -n 'spamhaus.org says: '
99 echo $(chk_adr ${rev_dns} 'sbl-xbl.spamhaus.org')
100
101 # See: http://ordb.org (Open mail relays)
102 echo -n ' ordb.org says: '
103 echo $(chk_adr ${rev_dns} 'relays.ordb.org')
104
105 # See: http://www.spamcop.net/ (You can report spammers here)
106 echo -n ' spamcop.net says: '
107 echo $(chk_adr ${rev_dns} 'bl.spamcop.net')
108
109 # # # other blacklist operations # # #
110
111 # See: http://cbl.abuseat.org.
112 echo -n ' abuseat.org says: '
113 echo $(chk_adr ${rev_dns} 'cbl.abuseat.org')
114
115 # See: http://dsbl.org/usage (Various mail relays)
116 echo
117 echo 'Distributed Server Listings'
118 echo -n ' list.dsbl.org says: '
119 echo $(chk_adr ${rev_dns} 'list.dsbl.org')
120
121 echo -n ' multihop.dsbl.org says: '
122 echo $(chk_adr ${rev_dns} 'multihop.dsbl.org')
123
124 echo -n 'unconfirmed.dsbl.org says: '
125 echo $(chk_adr ${rev_dns} 'unconfirmed.dsbl.org')
126
127 else
128 echo
129 echo 'Could not use that address.'
130 fi
131
132 exit 0
133
134 # Exercises:
135 # --------
136
137 # 1) Check arguments to script,
138 # and exit with appropriate error message if necessary.
139
140 # 2) Check if on-line at invocation of script,
141 # and exit with appropriate error message if necessary.
142
143 # 3) Substitute generic variables for "hard-coded" BHL domains.
144
145 # 4) Set a time-out for the script using the "+time=" option
146 to the 'dig' command.