|
数天前,我曾经发帖详细介绍了通过域名抢注发财的业务流程,朋友们反应热烈,有人加我问哪里有相关抢注代码
就像帖子 https://www.hostloc.com/thread-613066-1-1.html 说的,域名抢注需要代码的主要是两个地方 1.查询 whois 2.提交api
第二点 提交api的代码,这个主要得根据服务商提供的api文档进行编程
hexonet 的API文档地址 https://github.com/hexonet/hexonet-api-documentation/blob/master/API/DOMAIN/ADDDOMAIN.md
也有程序员为 hexonet 的api接口提供了一个PHP源码 https://github.com/al-one/hexonet-api
dynadot.com 的抢注API地址 https://www.dynadot.com/domain/api2.html ,它比较简单,只要一个get 或者 post 到一个地址 https://api.dynadot.com/api2.html?key=8S7I2s6Qd8g&command=register&domain=mydomain.com&duration=1
quyu.net 也有API接口,这个要向趣域客服申请,API PHP 示例代码 https://www.quyu.net/knowledgebase.php?action=displayarticle&id=23
关于第一点,通过PHP代码查询whois的方式主要有两个 1.CURL 2.SOCKET 下面就是相关代码
CURL
- const TIMEOUT = 30;
- const PORT = 43;
- const ESTR = 'Domain not found';
- function whois(string $domain, string $address): array
- {
- $curl = null;
- $output = '';
- $info = array();
- if (!function_exists('curl_version')) {
- trigger_error('cURL is not found!');
- } else {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $address);
- curl_setopt($curl, CURLOPT_PORT, PORT);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_TIMEOUT, TIMEOUT);
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $domain . "\r\n");
- $output = curl_exec($curl);
- curl_close($curl);
- $info['domain'] = $domain;
- (strstr($output, ESTR)) ? $info['status'] = 0 : $info['status'] = 1;
- (strstr($output, ESTR)) ? $info['description'] = '掉啦,赶紧抢吧' : $info['description'] = '卧槽,还没掉';
- $info['whois'] = $output;
- }
- return($info);
- }
- print_r(whois('a.dog','whois.nic.dog'));
复制代码
SOCKET
- const TIMEOUT = 30;
- const PORT = 43;
- const ESTR = 'Domain not found';
- function whois(string $domain, string $address): array
- {
- $output = '';
- $info = array();
- $connection = fsockopen($address, PORT, $errno, $errmessage, TIMEOUT);
- if (!$connection) {
- echo('Connection failed! ' . 'Error no: ' . $errno . ' Error message: ' . $errmessage);
- exit();
- } else {
- ($connection) ? fputs($connection, $domain . "\r\n") : $connection = null;
- if (!is_null($connection)) {
- while (!feof($connection)) $output .= fgets($connection);
- $info['domain'] = $domain;
- (strstr($output, ESTR)) ? $info['status'] = 0 : $info['status'] = 1;
- (strstr($output, ESTR)) ? $info['description'] = '掉啦,赶紧抢吧' : $info['description'] = '卧槽,还没掉';
- $info['whois'] = $output;
- } else {
- trigger_error('$connection variable is null!');
- exit();
- }
- }
- fclose($connection);
- return($info);
- }
- print_r(whois('a.dog','whois.nic.dog'));
复制代码
然后你找到一个定时任务的脚本,以一定的间隔执行PHP代码查询whois服务器,当发现某个域名掉了,立刻执行域名注册API即可
最后祝大家马到成功,财源滚滚
|
|