由两部分组成,一个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接口域名查询的更多相关文章

  1. 调用API接口,查询手机号码归属地(3)

    从mysql数据库获取电话号码,查询归属地并插入到数据库 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib, sys, pym ...

  2. 调用API接口,查询手机号码归属地(2)

    使用pymysql pip install pymysql 创建mysql测试表 CREATE TABLE `userinfo` ( `id` int(20) NOT NULL AUTO_INCREM ...

  3. 调用API接口,查询手机号码归属地(1)

    使用https://www.juhe.cn/提供的接口,查询归属地 在官网注册key即可使用. 代码如下 #!/usr/bin/python # -*- coding: utf-8 -*- impor ...

  4. 给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 ...

  5. 调用phone库,查询手机号码归属地(4)

    需要安装pymysql,phone库 #!/usr/bin/python # -*- coding: utf-8 -*- import sys, pymysql, logging, phone fro ...

  6. 【转】万网域名查询接口(API)的说明

    1.域名查询接口采用HTTP,POST,GET协议:调用URL:http://panda.www.net.cn/cgi-bin/check.cgi参数名称:area_domain 值为标准域名,例:h ...

  7. python3实现域名查询和whois查询

    关键字:python3 域名查询 域名查询接口 whois查询原文:http://www.cnblogs.com/txw1958/archive/2012/08/31/python3-domain-w ...

  8. 万网域名查询API接口

    域名查询 接口地址:http://panda.www.net.cn/cgi-bin/check.cgi 接口采用HTTP,POST,GET协议 参数名称:area_domain 值为标准域名,例:nm ...

  9. WebApi接口 - 如何在应用中调用webapi接口

    很高兴能再次和大家分享webapi接口的相关文章,本篇将要讲解的是如何在应用中调用webapi接口:对于大部分做内部管理系统及类似系统的朋友来说很少会去调用别人的接口,因此可能在这方面存在一些困惑,希 ...

随机推荐

  1. NekoHTML and Dom4j

    http://pro.ctlok.com/2010/07/java-read-html-dom4j-nekohtml.html package com.ctlok.pro; import java.i ...

  2. Java安全防御学习笔记V1.0

    Java安全防御学习笔记V1.0http://www.docin.com/p-766808938.html

  3. Linux操作系统的简单认识

    1:Linux操作系统的历史 Linux操作系统是由unix操作系统发展而来的,但是Unix是收费的系统,而Linux操作系统的免费的,开源的,所以使用比较广泛,但是它是基于命令行的,不提供图形化用户 ...

  4. 【字符串排序,技巧!】UVa 10905 - Children’s Game

    There are lots of number games for children. These games are pretty easy to play but not so easy to ...

  5. 【转载】最近在用Arrays的asList()生成的List时,List元素的个数时而不正确,数组转化为List,即Arrays.asList(intArray);

    最近在用Arrays的asList()生成的List时,List元素的个数时而不正确. Java代码 //经多次测试,只要传递的基本类型的数组,生成List的元素个数均为1 char arrc = { ...

  6. Exchanger, Changing data between concurrent tasks

    The Java concurrency API provides a synchronization utility that allows the interchange of data betw ...

  7. POJ 2127 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...

  8. 九度OJ 1351 数组中只出现一次的数字

    题目地址:http://ac.jobdu.com/problem.php?pid=1351 题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 输 ...

  9. 九度OJ 1513 二进制中1的个数

    题目地址:http://ac.jobdu.com/problem.php?pid=1513 题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样 ...

  10. OpenJudge/Poj 1159 Palindrome

    1.链接地址: http://bailian.openjudge.cn/practice/1159/ http://poj.org/problem?id=1159 2.题目: Palindrome T ...