php查询whois信息的方法

作者:不吃皮蛋 时间:2023-09-05 10:47:00 

本文实例讲述了php查询whois信息的方法。分享给大家供大家参考。具体如下:

这里使用php通过查询whois信息的网站列表进行查询


function whois_query($domain) {
 // fix the domain name:
 $domain = strtolower(trim($domain));
 $domain = preg_replace('/^http:\/\//i', '', $domain);
 $domain = preg_replace('/^www\./i', '', $domain);
 $domain = explode('/', $domain);
 $domain = trim($domain[0]);
 // split the TLD from domain name
 $_domain = explode('.', $domain);
 $lst = count($_domain)-1;
 $ext = $_domain[$lst];
 // You find resources and lists
 // like these on wikipedia:
 //
 // http://de.wikipedia.org/wiki/Whois
 //
 $servers = array(
   "biz" => "whois.neulevel.biz",
   "com" => "whois.internic.net",
   "us" => "whois.nic.us",
   "coop" => "whois.nic.coop",
   "info" => "whois.nic.info",
   "name" => "whois.nic.name",
   "net" => "whois.internic.net",
   "gov" => "whois.nic.gov",
   "edu" => "whois.internic.net",
   "mil" => "rs.internic.net",
   "int" => "whois.iana.org",
   "ac" => "whois.nic.ac",
   "ae" => "whois.uaenic.ae",
   "at" => "whois.ripe.net",
   "au" => "whois.aunic.net",
   "be" => "whois.dns.be",
   "bg" => "whois.ripe.net",
   "br" => "whois.registro.br",
   "bz" => "whois.belizenic.bz",
   "ca" => "whois.cira.ca",
   "cc" => "whois.nic.cc",
   "ch" => "whois.nic.ch",
   "cl" => "whois.nic.cl",
   "cn" => "whois.cnnic.net.cn",
   "cz" => "whois.nic.cz",
   "de" => "whois.nic.de",
   "fr" => "whois.nic.fr",
   "hu" => "whois.nic.hu",
   "ie" => "whois.domainregistry.ie",
   "il" => "whois.isoc.org.il",
   "in" => "whois.ncst.ernet.in",
   "ir" => "whois.nic.ir",
   "mc" => "whois.ripe.net",
   "to" => "whois.tonic.to",
   "tv" => "whois.tv",
   "ru" => "whois.ripn.net",
   "org" => "whois.pir.org",
   "aero" => "whois.information.aero",
   "nl" => "whois.domain-registry.nl"
 );
 if (!isset($servers[$ext])){
   die('Error: No matching nic server found!');
 }
 $nic_server = $servers[$ext];
 $output = '';
 // connect to whois server:
 if ($conn = fsockopen ($nic_server, 43)) {
   fputs($conn, $domain."\r\n");
   while(!feof($conn)) {
     $output .= fgets($conn,128);
   }
   fclose($conn);
 }
 else { die('Error: Could not connect to ' . $nic_server . '!'); }
 return $output;
}
// Some example queries:
print whois_query('jonasjohn.de');
print whois_query('example.com');
print whois_query('example.org');

希望本文所述对大家的php程序设计有所帮助。

标签:php,whois
0
投稿

猜你喜欢

  • Centos环境部署django项目的全过程(永久复用)

    2021-06-17 00:37:28
  • Python drop()删除行列的操作方法

    2022-10-27 17:12:41
  • Golang中Bit数组的实现方式

    2024-06-07 16:06:34
  • Pycharm配置autopep8实现流程解析

    2021-08-23 05:34:40
  • HTML中使背景图片自适应浏览器大小实例详解

    2024-05-02 16:18:32
  • 跟老齐学Python之变量和参数

    2023-01-12 22:23:31
  • python基于itchat实现微信群消息同步机器人

    2023-08-02 03:23:51
  • tensorflow-gpu2.3版本安装步骤

    2022-11-25 09:35:40
  • ASP下标越界错误的解决方法

    2008-10-19 17:39:00
  • node.js express安装及示例网站搭建方法(分享)

    2024-05-13 09:58:22
  • ASP基础知识介绍

    2009-02-11 13:44:00
  • 解决vue打包之后静态资源图片失效的问题

    2024-05-29 22:18:53
  • sql server 2008 忘记sa密码的解决方法

    2024-01-26 22:48:16
  • javaScript中一些常见的数据类型检查校验

    2023-07-02 05:19:09
  • 远程连接mysql 授权方法详解

    2024-01-23 10:28:02
  • Beego中ORM操作各类数据库连接方式详细示例

    2024-01-20 08:07:07
  • 登录EasyConnect后无法通过jdbc访问服务器数据库问题的解决方法

    2024-01-23 00:13:38
  • Python实现GUI学生信息管理系统

    2022-03-19 19:35:36
  • Linux下彻底卸载mysql详解

    2024-01-13 11:31:50
  • go语言中iota和左移右移的使用说明

    2024-04-25 15:16:55
  • asp之家 网络编程 m.aspxhome.com