PHP 脚本中 DNS_GET_RECORD MX 查找失败

发布于 2024-09-12 12:17:22 字数 1545 浏览 3 评论 0原文

我有一个 PHP 脚本,它使用 get_dns_record 检索并显示通过表单提交的域的特定 DNS 记录。

它工作得非常好,只是处理 MX 记录的部分有点不可靠。有时根本不显示任何 MX 记录(在我知道有这些记录的域上)。如果你刷新2-3次,有时它们就会出现。有时他们不会。

function getDNSRecord($domain1) {
    $dns = dns_get_record( $domain1, DNS_ANY );
    echo "These are DNS records";
    foreach( $dns as $d ) {
        // Only print A and MX records
        if( $d['type'] != "A" and $d['type'] != "MX" )
            continue;
    
        // Print type specific fields
        switch( $d['type'] ) {
            case 'A':
                // Display annoying message
                echo "<b>\n" . $d['ip'] . "</b>\n is the Primary A Record for this domain.";
                break;
            case 'MX':
                // Resolve IP address of the mail server
                $mx = dns_get_record( $d['target'], DNS_A );
                foreach( $mx as $server ) {
                    echo "This MX record for " . $d['host'] . " points to the server <b>\n" . $d['target'] . "</b>\n whose IP address is <b>\n" . $server['ip'] . "</b>. It has a priority of <b>\n" . $d['pri'] . "</b>\n.";
                }
            if ( $d['target'] == $domain1 ) {
                echo "<div id='mx-status'>There is an issue with this MX Record</div>\n";
                    } else {
                echo "<div id='mx-status'>This MX Record looks fine.</div>\n";
                }
                break;
        }
    }
}

I have a PHP script that is using get_dns_record to retrieve and display specific DNS records for a domain, submitted via a form.

It's working really well, except that the section that handles MX records is a little unreliable. Sometimes no MX Records are displayed at all (on domains I know have them). If you refresh 2-3 times, sometimes they will show up. Sometimes they won't.

function getDNSRecord($domain1) {
    $dns = dns_get_record( $domain1, DNS_ANY );
    echo "These are DNS records";
    foreach( $dns as $d ) {
        // Only print A and MX records
        if( $d['type'] != "A" and $d['type'] != "MX" )
            continue;
    
        // Print type specific fields
        switch( $d['type'] ) {
            case 'A':
                // Display annoying message
                echo "<b>\n" . $d['ip'] . "</b>\n is the Primary A Record for this domain.";
                break;
            case 'MX':
                // Resolve IP address of the mail server
                $mx = dns_get_record( $d['target'], DNS_A );
                foreach( $mx as $server ) {
                    echo "This MX record for " . $d['host'] . " points to the server <b>\n" . $d['target'] . "</b>\n whose IP address is <b>\n" . $server['ip'] . "</b>. It has a priority of <b>\n" . $d['pri'] . "</b>\n.";
                }
            if ( $d['target'] == $domain1 ) {
                echo "<div id='mx-status'>There is an issue with this MX Record</div>\n";
                    } else {
                echo "<div id='mx-status'>This MX Record looks fine.</div>\n";
                }
                break;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动听の歌 2024-09-19 12:17:22

您是否考虑过使用 getmxrr() 来获取域的 mx 记录?此处的文档: https://www.php.net/manual/en/function .getmxrr.php

Have you considered using getmxrr() to get the mx records for the domain? Documentation here: https://www.php.net/manual/en/function.getmxrr.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文