获取服务器的SPF记录

问题描述 投票:3回答:3

我需要使用PHP + Ext JS创建简单的代码,当任何域的SPF记录被加入并进一步处理时。

我找到了像http://www.kitterman.com/spf/validate.html这样的网站,我可以在网站上获得SPF记录。

但我需要在我的PHP + JS代码中使用此信息,我需要处理它,显示并保存新的更新的。

PHP JS中是否有任何命令可以获取SPF记录并保存?

Urmas。

php extjs dns spf
3个回答
5
投票

SPF是一个txt DNS记录,所以只需使用dns_get_record ($hostname , DNS_TXT)获取所有txt记录(它返回一个数组)并检查每个记录是否包含v=spf1


1
投票

您应该考虑到SPF标准非常复杂,并且有许多人做错了。我建议你更多地阅读它,以确保你的实现涵盖了你需要的所有检查。

这是了解更多SPF的非常好的资源:http://www.openspf.org/SPF_Record_Syntax

这是技术文档:http://tools.ietf.org/html/rfc4408

除了获取域的TXT记录之外,还有更多内容。对于早于5的PHP版本,您可以在基于unix的系统上使用shell_exec("dig example.com TXT @nameserver");


0
投票

检查此代码。这可能对某人有帮助

<?php
include("util.php");
$exists = false;
$array = dns_get_record("amazon.com", DNS_ALL);
for ($i = 0; $i <= count($array) - 1; $i++) {
    $nestedarray = $array[$i];
    for ($j = 0; $j <= count($nestedarray) - 1; $j++) {
        if (array_key_exists("txt", $nestedarray)) {
            $str = $nestedarray['txt'];
            $search = "v=spf1";
            if (preg_match("/{$search}/i", $str)) {
                echo (prepareAPIResponse("success", $str, "found"));
                $exists = true;
                break;
            }
        }
    }
}
if (!$exists) {
    echo (prepareAPIResponse("error", null, "not found"));
}

function prepareAPIResponse($status='success', $data=null, $msg=null)
{
    header('content-type: application/json');
    return json_encode([
       'status'=>$status,
       'data'=>$data,
       'message'=>$msg
    ]);
}
© www.soinside.com 2019 - 2024. All rights reserved.