php调用whois接口域名查询
由两部分组成,一个index.php文件,一个whois的接口文件;
<html>
<head>
<title>域名到期查询</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
$(document).ready(function(){
$(".dj").toggle(function(){
$(".info_main").show();
$(".dj").text("-")},
function(){
$(".info_main").hide();
$(".dj").text("+")}
);
});
</script>
<h1>域名到期查询:</h1>
<form class="yuming_form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<ul>
<li>
<span>输入域名:</span><input class="yuming_txt" type="text" name="yuming" /><input class="yuming_btn" type="submit" value="查询" />
</li>
</form>
<?php
include "whois.php";
?>
<div class="info_tit">详情:<span class="dj">+</span></div>
<div class="info_main">
<?php
//查询域名是否被注册,等价于 $sd->PrintSta();
$rs = $sd->GetInfo();
if($rs=="ok") echo $sd->domain." 未注册!<br/>\r\n";
else if($rs=="") echo "无法查询 ".$sd->domain." 状态!<br/>\r\n";
else echo $sd->domain." 已注册,到期时间:$rs<br/>\r\n";
//获得域名的详细whois信息
echo $sd->GetWhois();
?>
</div>
</body>
</html>
whois.php
<?php
class SearchDomain{
var $domain="";
function SetDomain($udomain){
$this->domain = $udomain;
}
//
// 获取whois并分析域名状态
// ok 未被注册
// 非空值 过期时间
// 空值 未知
//
function GetInfo(){
/*
$dinfo = trim($this->GetWhois());
if($dinfo=="") return "";
if(eregi("no match",$dinfo)) return "ok";
//return $rs;
*/
$wl = "";
$w_server = $this->GetServer();
if($w_server=="") return "";
$fp = fsockopen($w_server, 43, $errno, $errstr, 30);
if(!$fp){
echo $errstr;
return "";
} $out = $this->domain."\r\n";
$out .= "Connection: Close\r\n\r\n";
fputs($fp, $out); while (!feof($fp)){
$wl = fgets($fp, 255); if(eregi("no match",$wl)){
fclose($fp);
return "ok";
}
if(eregi("Expiration Date",$wl)){
$lines = split(":",$wl);
$t = trim($lines[1]);
$ts = split(" ",$t);
$t = $ts[0];
if(ereg("[^0-9-]",$t)){
$ts = split("-",$t);
$t = $ts[2]."-".$this->MonthToNum($ts[1])."-".$ts[0];
}
fclose($fp);
return $t;
}
}
fclose($fp);
return "";
}
//
//获得域名的整个whois信息
//
function GetWhois(){
$wh = "";
$w_server = $this->GetServer();
if($w_server=="") return "";
$fp = fsockopen($w_server, 43, $errno, $errstr, 30); if(!$fp){
echo $errstr;
return "";
}
$out = $this->domain."\r\n";
$out .= "Connection: Close\r\n\r\n";
fputs($fp, $out);
while (!feof($fp)){
$wh .= nl2br(fgets($fp, 255));
}
fclose($fp);
return $wh;
}
//
//输出当前域名的状态信息
//
function PrintSta(){
$rs = $this->GetInfo();
if($rs=="ok") echo "<li>" . "<font>".$this->domain."</font>" . " 未注册!</li>";
else if($rs=="") echo "<li>" . "无法查询 " . "<font>".$this->domain."</font>" . " 状态!</li>";
else echo "<li>" . "<font>" . $this->domain."</font>" . " 已注册,到期时间:<font>$rs</font></li>";
}
//
//获得 whois 查询服务器
//
function GetServer(){
$udomain=substr($this->domain,-3);
switch($udomain){
case "com":
$w_server="whois.internic.net";
break;
case "net":
$w_server="whois.internic.net";
break;
case "org":
$w_server="whois.pir.org";
break;
case "nfo":
$w_server="whois.afilias.info";
break;
case "biz":
$w_server="whois.biz";
break;
case ".cc":
$w_server="whois.nic.cc";
break;
case "edu":
$w_server="whois.educause.net";
break;
case "gov":
$w_server="whois.nic.gov";
break;
case ".cn":
$w_server="whois.cnnic.net.cn";
break;
default:
$w_server="";
}
return $w_server;
}
//
//英语的月份转为数字
//
function MonthToNum($m){
$m = strtolower($m); for($i=1;$i<=12;$i++){
$tt = mktime(0,0,0,$i+1,0,2005);
if($m==strtolower(strftime("%b",$tt))){
if($i>9) return $i;
else return "0".$i;
}
}
}
}
//接收域名值
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$yuming = test_input($_POST["yuming"]);
} function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
/* echo $yuming; */
$sd = new SearchDomain();
$sd->SetDomain($yuming);
$sd->PrintSta();
//查询域名是否被注册,等价于 $sd->PrintSta();
//$rs = $sd->GetInfo();
//if($rs=="ok") echo $sd->domain." 未注册!<br/>\r\n";
//else if($rs=="") echo "无法查询 ".$sd->domain." 状态!<br/>\r\n";
//else echo $sd->domain." 已注册,到期时间:$rs<br/>\r\n";
//获得域名的详细whois信息
//echo $sd->GetWhois();
?>
注意两点:
1,index.php要include一下whois文件。
2,通过post方式传name = "yuming"这个值来实现查询,index.php传,whois.php接收。
接收方式
//接收域名值
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$yuming = test_input($_POST["yuming"]);
} function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
php调用whois接口域名查询的更多相关文章
- 调用API接口,查询手机号码归属地(3)
从mysql数据库获取电话号码,查询归属地并插入到数据库 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib, sys, pym ...
- 调用API接口,查询手机号码归属地(2)
使用pymysql pip install pymysql 创建mysql测试表 CREATE TABLE `userinfo` ( `id` int(20) NOT NULL AUTO_INCREM ...
- 调用API接口,查询手机号码归属地(1)
使用https://www.juhe.cn/提供的接口,查询归属地 在官网注册key即可使用. 代码如下 #!/usr/bin/python # -*- coding: utf-8 -*- impor ...
- 给MySQL增加mysql-udf-http和mysql-udf-json自定义函数,让MySQL有调用http接口和查询直接回JSON的能力
1.安装mysql-udf-httpyum install -y libcurl*下载地址:http://pan.baidu.com/s/1nuYZqR3tar zxvf mysql-udf-http ...
- 调用phone库,查询手机号码归属地(4)
需要安装pymysql,phone库 #!/usr/bin/python # -*- coding: utf-8 -*- import sys, pymysql, logging, phone fro ...
- 【转】万网域名查询接口(API)的说明
1.域名查询接口采用HTTP,POST,GET协议:调用URL:http://panda.www.net.cn/cgi-bin/check.cgi参数名称:area_domain 值为标准域名,例:h ...
- python3实现域名查询和whois查询
关键字:python3 域名查询 域名查询接口 whois查询原文:http://www.cnblogs.com/txw1958/archive/2012/08/31/python3-domain-w ...
- 万网域名查询API接口
域名查询 接口地址:http://panda.www.net.cn/cgi-bin/check.cgi 接口采用HTTP,POST,GET协议 参数名称:area_domain 值为标准域名,例:nm ...
- WebApi接口 - 如何在应用中调用webapi接口
很高兴能再次和大家分享webapi接口的相关文章,本篇将要讲解的是如何在应用中调用webapi接口:对于大部分做内部管理系统及类似系统的朋友来说很少会去调用别人的接口,因此可能在这方面存在一些困惑,希 ...
随机推荐
- CentOS7 service/chkconfig replace commands
对比表,以 apache / httpd 为例 任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 httpd on systemctl enable httpd.serv ...
- UNIX V6内核源码剖析——进程
进程的概念 1. 什么是进程 2. 进程的并行执行 3. 进程的运行状态 4. 用户模式和内核模式 cpu具有2种模式——内核模式和用户模式,通过PSW来切换. 切换时, 映射到虚拟地址的物理内存区域 ...
- matlab中num2str的应用
在求导数,积分,方程的过程中,难免会遇到一些参数要随着情况有点变化,这时,你就需要能够动态的表示出你的表达式,Num2str函数是一个相当有用的函数,一般配合[]连接符使用,下面将我接触到的一些用法写 ...
- dedecms自定义函数(二次开发)
一些功能可能dedecms没有,这个时候可以自己写一些函数: 1.打开inlude->extend.func.php,将函数写到里面 比如:前台: [field:id function=&quo ...
- JavaScript检测实例属性, 原型属性
0.前提 JavaScript对象的属性分为两种存在形态. 一种是存在实例中, 另一是存在原型对象中. 根据上述, 检测属性的时候会出现4种情况 既不存在实例中, 也不存在原型对象中 存在实例中, 不 ...
- 搭建scala开发环境
下载scala 2.11.5 安装eclipse LUNA版本 安装scala IDE插件:http://download.scala-ide.org/sdk/lithium/e44/scala211 ...
- Jquery方法大全
一.JQuery常用的方法 :(JQuery中90%都是方法,没有参数是获取,带参数是设置) $("#id").css('backgroundColor','blue'); .cs ...
- 通过公网连接云数据库Memcache--ECS Windows篇
目前云数据库Memcache是需要通过ECS的内网进行连接访问,如果用户本地需要通过公网访问云数据库Memcache,可以在ECS Windows云服务器中通过netsh进行端口映射实现. 一.搭建要 ...
- MySQL与NoSQL——SQL与NoSQL的融合
来源:http://www.cnblogs.com/sunli/archive/2011/05/11/mysql-nosql.html 写这一篇内容的原因是MySQL5.6.2突然推出了memcach ...
- Sublime Text2上搭建C/C++环境
环境:Sublime Text2 win7 64位 1.下载Sublime Text2并安装 下载地址:http://www.sublimetext.com/ 2.需要用 ...