域名过期时间查询代码 - 缥缈博客-个人技术博客

域名过期时间查询代码

作者: 缥缈     发布于「 技术教程 」 - 缥缈博客-个人技术博客

2021-4-25 分类: 技术教程 评论(0)
当前位置:首页 > 技术教程 > 正文

作者: 缥缈

个人技术博客

手机扫码查看

标签:

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

通过抓取站长工具的过期查询来实现,下面是实现代码:

<?php
header('Content-type: application/json');
$domain = isset($_REQUEST['domain']) ? $_REQUEST['domain'] : '';
if ($domain == '') {
    exit(json_encode(['code' => 201, 'msg' => '缺少domain参数'], JSON_UNESCAPED_UNICODE));
}
if (!preg_match('/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/', $domain)) {
    exit(json_encode(['code' => 202, 'msg' => '域名格式有误'], JSON_UNESCAPED_UNICODE));
}
$data = domain('http://whois.chinaz.com/' . $domain);
preg_match('/创建时间<\/div><div class=\"fr WhLeList-right\"><span>(.*?)<\/span><\/div><\/li>/', $data, $reg);
preg_match('/过期时间<\/div><div class=\"fr WhLeList-right\"><span>(.*?)<\/span>/', $data, $over);
$reg = $reg[1];
$over = $over[1];
if ($reg == '' || $over == '') {
    exit(json_encode(array('code' => 203, 'msg' => '查询失败', 'domain' => $domain), JSON_UNESCAPED_UNICODE));
} else {
    exit(json_encode(array('code' => 200, 'msg' => '查询成功', 'domain' => $domain, 'reg' => $reg, 'over' => $over), JSON_UNESCAPED_UNICODE));
}

function domain($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
    $httpheader[] = "Accept-Encoding: gzip, deflate, sdch, br";
    $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if ($header) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($cookie) {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if ($referer) {
        if ($referer == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://whois.chinaz.com/');
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $referer);
        }
    }
    if ($ua) {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
    }
    if ($nobaody) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_TIMEOUT, 3);
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}
分享到:
未经允许不得转载:

作者: 缥缈, 转载或复制请以 超链接形式 并注明出处 缥缈博客-个人技术博客
原文地址: 《域名过期时间查询代码》 发布于2021-4-25

评论

切换注册

登录

您也可以使用第三方帐号快捷登录

切换登录

注册

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏