-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmethod.whois-socket.php
71 lines (60 loc) · 2.04 KB
/
method.whois-socket.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require('./config.variables.php');
if (!function_exists('search')) {
/**
* Search more than one extension
* @param string $name
* @param array $extensions
* @return array
* @example search('emrecanoztas', array('com', 'net'));
*/
function search(string $name, array $extensions): array
{
$domain = '';
$address = '';
$output = '';
$info = array();
foreach ($extensions as $extension) {
if (array_key_exists($extension, EXTENSION_LIST)) {
$address = EXTENSION_LIST[$extension];
$domain = $name . '.' . $extension;
array_push($info, whois($domain, $address));
}
}
return($info);
}
}
if (!function_exists('whois')) {
/**
* Getting information about domain.
* @param string $domain
* @param string $address
* @return array
*
* @example whois('emrecanoztas.com', 'whois.crsnic.net')
*/
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, 'No match for')) ? $info['status'] = 0 : $info['status'] = 1;
!(strstr($output, 'No match for')) ? $info['description'] = 'Not available' : $info['description'] = 'Available';
$info['whois'] = $output;
} else {
trigger_error('$connection variable is null!');
exit();
}
}
fclose($connection);
return($info);
}
}