diff --git a/index.html b/index.html
new file mode 100644
index 0000000..fdd855b
--- /dev/null
+++ b/index.html
@@ -0,0 +1,19 @@
+
+
+
+
+ Inspect Mail
+
+
+
+
+To get NS, MX and SPF records for the domain, make sure you test a FQDN that has a valid A record.
domain.tld should work.
+
+
+
diff --git a/inspect-mail.php b/inspect-mail.php
new file mode 100644
index 0000000..dee716f
--- /dev/null
+++ b/inspect-mail.php
@@ -0,0 +1,166 @@
+Mail Server field is empty.';
+ die;
+}
+
+echo '
+ To get: NS, MX and SPF records for the domain, make sure you test a FQDN that has a valid A record.
domain.tld should work.
';
+
+// Identify, set data and report info
+if ( filter_var( $_POST['domain'] , FILTER_VALIDATE_IP ) ) {
+ $isIP = true;
+} else {
+ $isIP = false;
+}
+
+if ( $isIP ) {
+ $ip = $_POST['domain'];
+ $host = $ip;
+} else {
+ $host = strtolower( $_POST['domain'] );
+ $ip = gethostbyname( $host );
+
+ // Get nameservers for the domain
+ $dns = dns_get_record( $host , DNS_NS );
+
+ // Get MX for the domain
+ $dnsmx = dns_get_record( $host , DNS_MX );
+
+ // Get SPF for the domain
+ $dnstxt = dns_get_record( $host , DNS_TXT );
+
+ // Die if Cloud Flare domain
+ if ( $dns ) {
+ foreach ( array_reverse( $dns ) as $ns ) {
+ if ( strpos( $ns['target'] , 'cloudflare.com' ) !== false ) {
+ echo 'This is a Cloud Flare domain. Data can\'t be collected for this domain.';
+ die;
+ }
+ }
+ }
+
+ if ( $ip == $host ) {
+ echo 'IP address has not been found for the given domain name.
';
+ die;
+ } else {
+ echo 'Domain Info
Domain: ' . $host .'
IP address: ' . $ip . '
';
+ }
+
+ // Print nameservers for the domain
+ if ( $dns ) {
+ echo 'Name Server
';
+ foreach ( array_reverse( $dns ) as $ns ) {
+ echo $ns['target'] . '
';
+ }
+ }
+
+ // Print MX for the domain
+ if ( $dnsmx ) {
+ echo 'MX record
';
+ foreach ( array_reverse( $dnsmx ) as $nmx ) {
+ echo $nmx['target'] . '
';
+ }
+ }
+
+ // Print SPF for the domain
+ if ( $dnstxt ) {
+ echo 'SPF record
';
+ foreach ( $dnstxt as $ntxt ) {
+ if ( strpos( $ntxt['txt'], 'v=spf1' ) !== false ) {
+ if ( strpos( $ntxt['txt'], $ip ) !== false ) {
+ echo '' . $ntxt['txt'] . '
';
+ } elseif ( strpos( $ntxt['txt'], '.' . $host ) !== false ) {
+ echo '' . $ntxt['txt'] . '
';
+ } elseif ( strpos( $ntxt['txt'], $host ) !== false ) {
+ echo '' . $ntxt['txt'] . '
';
+ } else {
+ echo '' . $ntxt['txt'] . '
';
+ }
+ }
+ }
+ }
+}
+
+// Print PTR for an IP
+echo 'PTR record the IP address
';
+echo 'Note: No valid PTR record will be retrieved for the IP address of the server that is hosting this script.
';
+
+$ptr = gethostbyaddr( $ip );
+if ( ! $ptr || $ptr == $ip ) {
+ echo 'No PTR record found.';
+} elseif ( $ptr == $host ) {
+ echo '' . $ptr . '';
+} elseif ( strpos( $ptr, $host ) !== false ) {
+ echo '' . $ptr . '';
+} elseif ( $isIP ) {
+ echo $ptr;
+} else {
+ echo '' . $ptr . '';
+}
+
+// Ports
+$ports = array( 25, 110, 143, 465, 587, 993, 995 );
+
+// Non SSL ports
+$nonssl = array( 25, 110, 143 );
+
+echo 'Mail Ports
';
+foreach ( $ports as $port ) {
+ $connection = @fsockopen( $host, $port, $errno, $errstr, 1 );
+ if ( is_resource( $connection ) ) {
+ echo '' . $host . ': ' . $port . ' (' . getservbyport( $port, 'tcp' ) . ') is open.
';
+ fclose( $connection );
+ } else {
+ echo '' . $host . ': ' . $port . ' is not responding.
';
+ $nonssl[] = $port;
+ }
+}
+
+// Removing closed ports
+$sslports = array_diff( $ports, $nonssl );
+
+if ( count( $sslports ) != 0 ) {
+ echo 'SSL Cert on Ports
';
+}
+
+foreach ( $sslports as $sslport ) {
+ $url = "tcp://" . $host;
+ $orignal_parse = parse_url( $url, PHP_URL_HOST );
+ $get = stream_context_create(array(
+ "ssl" => array(
+ 'capture_peer_cert' => true,
+ 'verify_peer' => false,
+ 'verify_peer_name' => false ) ) );
+ $read = stream_socket_client( "ssl://" . $orignal_parse . ":" . $sslport, $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $get );
+ $cert = stream_context_get_params( $read );
+ $certinfo = openssl_x509_parse( $cert['options']['ssl']['peer_certificate'] );
+
+ // Print cert data
+ echo 'Certificate on port: ' . $sslport . '
';
+ if ( ! empty( $certinfo['subject']['CN'] ) ) {
+ if ( $certinfo['subject']['CN'] == $host ) {
+ echo 'Common Name: ' . $certinfo['subject']['CN'] . '
';
+ } else {
+ echo 'Common Name: ' . $certinfo['subject']['CN'] . '
';
+ }
+ echo 'Issuer: ' . $certinfo['issuer']['CN'] . '
';
+ echo 'Valid From: ' . gmdate( 'r', $certinfo['validFrom_time_t'] ) . '
';
+ if ( strtotime( $certinfo['validTo_time_t'] ) > time() ) {
+ echo 'Valid To: ' . gmdate( 'r', $certinfo['validTo_time_t'] ) . '';
+ } else {
+ echo 'Valid To: ' . gmdate( 'r', $certinfo['validTo_time_t'] ) . '';
+ }
+ }
+ else {
+ echo 'There is no certificate on the port.';
+ }
+}