我有一个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;
}
}
}
字符串
1条答案
按热度按时间oewdyzsn1#
您是否考虑过使用
getmxrr()
来获取域的mx记录?文档在此:https://www.php.net/manual/en/function.getmxrr.php