DNS_GET_RECORD'www'记录?

时间:2010-06-22 00:04:36

标签: php dns

我使用的是一个PHP脚本,它使用dns_get_record来检查域的A和MX记录。域名是通过简单的表格输入的。但是,我在向域变量添加“www”时遇到了一些问题。

我想为www.domain.com添加A Record查找。如何添加www?

<?php

$domain = $_POST["Domain"];

$dns = dns_get_record( $domain, DNS_ANY );
foreach( $dns as $d ) {
    // Only print A and MX records
    if( $d['type'] != "A" and $d['type'] != "MX" )
        continue;
    // First print all fields
    echo "For " . $d['host'] . ": <br />\n";
//    foreach( $d as $key => $value ) {
//        if( $key != "host" )    // Don't print host twice
//            echo " {$key}: <b>\n {$value}</b>\n <br />\n";
//     }
    // 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. <br /><br />\n";
            break;
        case 'MX':
            // Resolve IP address of the mail server
            $mx = dns_get_record( $d['target'], DNS_A );
            foreach( $mx as $server ) {
                echo "The 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. <br /><br />\n";
            }
        if ( $d['target'] == $domain ) {
            echo "<i>It looks like the domain is using itself as an MX Record.  You will need to create additional records.</i><br /><br />\n";
                } else {
            echo "<i>This MX Record looks fine.</i><br /><br />\n";
            }
            break;
    }
}

error_reporting(E_ALL);

?>

1 个答案:

答案 0 :(得分:1)

我建议将代码放入函数中:

function getDNSRecord($domain) {
$dns = dns_get_record( $domain, DNS_ANY );
foreach( $dns as $d ) {
    // Only print A and MX records
    if( $d['type'] != "A" and $d['type'] != "MX" )
        continue;
    // First print all fields
    echo "For " . $d['host'] . ": <br />\n";
//    foreach( $d as $key => $value ) {
//        if( $key != "host" )    // Don't print host twice
//            echo " {$key}: <b>\n {$value}</b>\n <br />\n";
//     }
    // 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. <br /><br />\n";
            break;
        case 'MX':
            // Resolve IP address of the mail server
            $mx = dns_get_record( $d['target'], DNS_A );
            foreach( $mx as $server ) {
                echo "The 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. <br /><br />\n";
            }
        if ( $d['target'] == $domain ) {
            echo "<i>It looks like the domain is using itself as an MX Record.  You will need to create additional records.</i><br /><br />\n";
                } else {
            echo "<i>This MX Record looks fine.</i><br /><br />\n";
            }
            break;
    }
}
}

然后两次调用该函数:

getDNSRecord($_POST['Domain']);
getDNSRecord('www.'.$_POST['Domain']);