Simple php script to generate an IP address list of DNS MX and SPF entries for a given domain.
To implement dynamic firewall rules (e.g. using an URL Table alias in pfsense or in pfBlockerNG) this scipt resolves both MX and SPF entries and presents the result as text/plain list. It can be used e.g. to allow traffic to and from mail servers accociated with a given domain.
A mail exchanger record (MX record) is a type of resource record in the Domain Name System that specifies a mail server responsible for accepting email messages on behalf of a recipient's domain, and a preference value used to prioritize mail delivery if multiple mail servers are available. The set of MX records of a domain name specifies how email should be routed with the Simple Mail Transfer Protocol (SMTP).
Source: Wikipedia, retreived 16.03.2016
The Sender Policy Framework (SPF) is an open standard specifying a technical method to prevent sender address forgery. More precisely, the current version of SPF — called SPFv1 or SPF Classic — protects the envelope sender address, which is used for the delivery of messages. See the box on the right for a quick explanation of the different types of sender addresses in e-mails.
Source: Sender Policy Framework, retreived 16.03.2016
## Installation
This script depends on php and rephluX's spf-resolver (and thus on composer).
Run this in your terminal to get the latest Composer version:
(check composer for current instructions!) and https://getcomposer.org/ for more information.)
php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === '41e71d86b40f28e771d4bb662b997f79625196afcca95a5abf44391188c695c6c1456e16154c75a211d238cc3bc5cb47') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Run the following command in your terminal to install spf-resolver:
php composer.phar install
## Usage
http://your.server/path/to/mailhost-resolver/index.php&domain={domainname}&IPv=[4|6]&type=[mx|spf]
(values in brackets [] are alternatives! See below.)
If your server is configured to run index.php as the default file name for a directory, you can shorten it to:
http://your.server/path/to/mailhost-resolver/&domain={domainname}&IPv=[4|6]&type=[mx|spf]
The script supports the following parameters (case sensitive):
Should accept any valid domain name (currently limited to 300 chars, see source). To support Internationalized domain names, the intl php extension needs to be installed and enabled.
Limits the result to addresses from the given IP address version, or all if not given.
Limits the result to addresses from the given DNS ressource records, or all if not given.
--- $Revision: 3458 $