如何获取域的mx记录

时间:2017-08-10 06:57:04

标签: php

我想了解mx记录的详细信息......但我不知道如何在我的代码中获取mx记录目标... 我得到了mx记录的详细信息。如何在我的代码中显示mx目标... 使用PHP,ping SMTP服务器并检查MX记录?我愿意写一个这样的剧本:

我的代码是:

  // Queries the DNS server for MX entries of a certain domain.
protected function mx_query($domain) {
    $hosts = array();
    $weight = array();
    if (function_exists('getmxrr')) {
        getmxrr($domain, $hosts, $weight);
    } else {
        $this->getmxrr($domain, $hosts, $weight);
    }
    return array($hosts, $weight);
}

// Provides a windows replacement for the getmxrr function.
protected function getmxrr($hostname, &$mxhosts, &$mxweights) {
    if (!is_array($mxhosts)) {
        $mxhosts = array();
    }
    if (!is_array($mxweights)) {
        $mxweights = array();
    }
    if (empty($hostname)) {
        return;
    }
    $cmd = 'nslookup -type=MX ' . escapeshellarg($hostname);
    if (!empty($this->mx_query_ns)) {
        $cmd .= ' ' . escapeshellarg($this->mx_query_ns);
    }
    exec($cmd, $output);
    if (empty($output)) {
        return;
    }
    $i = -1;
    foreach ($output as $line) {
        $i++;
        if (preg_match("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) {
            $mxweights[$i] = trim($parts[1]);
            $mxhosts[$i] = trim($parts[2]);
        }
        if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) {
            $mxweights[$i] = $i;
            $mxhosts[$i] = trim($parts[1]);
        }
    }
    return ($i != -1);
}

        if($this->check_mx){
        $check_mx = $this->check_mx($domain);
        if(!$check_mx){
            $output['result']['errors']['check_mx'] = 'Domain failed MX check.';
            $output['result']['success'] = 0;
        }else{
            $output['result']['report']['check_mx'] = $output['result']['report']['target'];


        }
    }

1 个答案:

答案 0 :(得分:0)

查看PHP pm2 start --name “UID” main.js(和pm2 show 0)方法(以及documentation pages上的给定示例)。