php查询域名注册状态

php查询whois信息的代码,收藏~

  1. <?php
  2. function checkDomain($domain,$server,$findText){
  3. // Open a socket connection to the whois server
  4. $con = fsockopen($server, 43);
  5. if (!$con) return false;
  6.  
  7. // Send the requested doman name
  8. fputs($con, $domain.”rn);
  9.  
  10. // Read and store the server response
  11. $response = ‘ :’;
  12. while(!feof($con)) {
  13.  
  14.  
  15. $response .= fgets($con,128);
  16. }
  17.  
  18. // Close the connection
  19. fclose($con);
  20.  
  21. // Check the response stream whether the domain is available
  22. if (strpos($response, $findText)){
  23. return true;
  24. }
  25. else {
  26. return false;
  27. }
  28. }
  29.  
  30. function showDomainResult($domain,$server,$findText){
  31. if (checkDomain($domain,$server,$findText)){
  32. echo “<tr><td>$domain</td><td>AVAILABLE</td></tr>”;
  33. }
  34. else echo “<tr><td>$domain</td><td>TAKEN</td></tr>”;
  35. }
  36. ?>
  37.  
  38. <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “DTD/xhtml1-transitional.dtd”>
  39. <html>
  40. <head>
  41. <title>MicroWhois domain checker</title>
  42. <link href=”style/style.css” rel=”stylesheet” type=”text/css” />
  43. </head>
  44. <body>
  45. <div id=”main”>
  46. <div id=”caption”>DOMAIN LOOKUP</div>
  47. <div id=”icon”>&nbsp;</div>
  48. <form action=”<?php echo $_SERVER['PHP_SELF']; ?>” method=”post” name=”domain” id=”domain”>
  49. Domain name:
  50. <table>
  51. <tr><td><input class=”text” name=”domainname” type=”text” size=”36″/></td></tr>
  52. <tr>
  53. <td>
  54. <input type=”checkbox” name=”all” checked />All
  55. <input type=”checkbox” name=”com”/>.com
  56. <input type=”checkbox” name=”net”/>.net
  57. <input type=”checkbox” name=”org”/>.org
  58. <input type=”checkbox” name=”info”/>.info
  59. </td></tr>
  60. <tr><td align=”center”><br/><input class=”text” type=”submit” name=”submitBtn” value=”Check domain”/></td></tr>
  61. </table>
  62. </form>
  63. <?php
  64. if (isset($_POST['submitBtn'])){
  65. $domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : ”;
  66. $d_all = (isset($_POST['all'])) ? ‘all’ : ”;
  67. $d_com = (isset($_POST['com'])) ? ‘com’ : ”;
  68. $d_net = (isset($_POST['net'])) ? ‘net’ : ”;
  69. $d_org = (isset($_POST['org'])) ? ‘org’ : ”;
  70. $d_info = (isset($_POST['info'])) ? ‘info’ : ”;
  71.  
  72. // Check domains only if the base name is big enough
  73. if (strlen($domainbase)>2){
  74. ?>
  75. <div id=”caption”>RESULT</div>
  76. <div id=”icon2″>&nbsp;</div>
  77. <div id=”result”>
  78. <table width=”100%”>
  79. <?php
  80. if (($d_com != ”) || ($d_all != ”) ) showDomainResult($domainbase.”.com”,’whois.crsnic.net’,'No match for’);
  81. if (($d_net != ”) || ($d_all != ”) ) showDomainResult($domainbase.”.net”,’whois.crsnic.net’,'No match for);
  82. if (($d_org != ”) || ($d_all != ”) ) showDomainResult($domainbase.”.org”,’whois.publicinterestregistry.net’,'NOT FOUND’);
  83. if (($d_info != ”) || ($d_all != ”) ) showDomainResult($domainbase.”.info”,’whois.afilias.net’,'NOT FOUND);
  84. ?>
  85. </table>
  86. </div>
  87. <?php
  88. }
  89. }
  90. ?>
  91. <div id=”source”>Micro Whois 1.1</div>
  92. </div>
  93. </body>

一条评论

  1. well, hi admin adn people nice forum indeed. how’s life? hope it’s introduce branch ;)