iprange2access - Perl script for generating records in format acceptable for sendmail access file from IP range.
iprange2access first_ip_in_range [ - ] last_ip_in_range [ -d [ -v ] [ -e errorcode ] [ -m message ] ] [ -V ] [ -h ]
Sendmail is one of the oldest mail servers for Unix. By default, Sendmail reads access lists from /etc/mail/access file. That file have role of configuration file used for defining mail or IP addresses which should be denied. Beside mail and IP addresses which could be defined in that file, the whole ranges of IP addresses could be defined too. Wrestling with spam, sometimes requires entering a huge number of lines which defines some range of IP addresses. After I entered 7557th line manually (it seems that I am very patient man), I decided that it is the time for writing script which will make this hard job a lot easier. So, I wrote script which can take range of IP addresses and output lines in format acceptable for sendmail access file. The script is written in perl. IPrange2access requires NetAddr::IP perl module which could be found on CPAN pages. Thanks to Daniel Spiljar email@example.com for helping me with perl. Thanks to him, this script is written in perl. At the first place I intented to wrote the script in bash. I beleve that I would spent a little more time and much more lines of code. In the iprange2access distribution you will find two perl scripts. iprange2access script will work with older perl and does not use any additional perl modules while iprange2access2 will work only with perl >= 5.8.0 and the NetAddr::IP perl module installed. By writting those scripts I was actually learning perl. This is the main reason for having two scripts which are doing the same thing. By running make install, only iprange2access script will be installed. If you want to use iprange2access2 script, just copy it to /usr/local/bin directory.
There is no need for screenshots but the usual output look like this:
$ iprange2access 192.168.14.5 192.168.14.8
$ iprange2access 192.168.14.254 - 192.168.17.1
$ iprange2access 192.168.12.254-192.168.17.1 -d -v -e 571 -m "No spam wanted"
192.168.14.254 571 No spam wanted
192.168.14.255 571 No spam wanted
192.168.15 571 No spam wanted
192.168.16 571 No spam wanted
192.168.17.0 571 No spam wanted
192.168.17.1 571 No spam wanted
This option will tell to script to generate a deny line (format acceptable for sendmail access) Without this option, script will output only IP addresses in range.
This option will result with prepending line #<IP range> on the top and appending line #</IP range> to the end of output. This is useful for recognise IP ranges in sendmail access file. This option make sens only if parameter -d is used too.
This option can owerride default errorcode which will be used if script is started with -d parameter. Default errorcode is 571.
This option can owerride default message with reason of bouncing mail from some IP address. This option make sens only if parameter -d is used too. Default message is: Because of previous SPAM activity from your domain, we reject your mail.
This option indicates that iprange2access should print version and exit.
This option indicates that iprange2access should print usage screen and exit.
This script is using NetAddr::IP perl module which could be found on CPAN pages. If you do not have NetAddr::IP perl module installed, you have to modify the script and set variable MODE to "core".
Current version of IPrange2access does not contain known bugs.
/etc/mail/access - Sendmail's access file
ERRORCODE_DEFAULT - default errorcode for sendmail access
MESSAGE_DEFAULT - default error message for sendmail access
MODE - you can set it to "core" if you do not have installed NetAddr::IP perl module, otherwise set it to "module"
sendmail(8), Sendmail documentation (/usr/share/doc/sendmail)
Josip Deanovic firstname.lastname@example.org