-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomainTools.php
120 lines (98 loc) · 3.11 KB
/
DomainTools.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
require_once 'iniparser.php';
class Domtooz
{
// Please reference: http://data.iana.org/TLD/tlds-alpha-by-domain.txt
// To find whois servers: https://gwhois.org
private static $domain_file = 'domains.ini';
/**
* Returns true or false
* indicating whether or not the URL
* passes a TLD check.
*/
public static function checkTLD($host)
{
// TODO: do a file exist check here
$tlds = iniParser(self::$domain_file);
return preg_match('/\.('.implode('|', array_keys($tlds)).')$/i', $host);
}
public static function explodeTLD($address)
{
if (strpos($address, '@') !== FALSE)
{
list(, $tld) = explode('@', $address, 2);
return (string) $tld;
}
else
{
return FALSE;
}
}
// Whois sever lookup function
public static function queryWhois($domain, $registrar = NULL)
{
// fixing the domain name format
$domain = strtolower(trim($domain));
$domain = preg_replace("/^http:\/\//i", '', $domain);
$domain = preg_replace("/^www\./i", '', $domain);
$domain = explode('/', $domain);
$domain = trim($domain[0]);
// server output string
$output = FALSE;
if (empty($registrar))
{
$servers = array();
// retrieving server resoures and lists
foreach (iniParser(self::$domain_file) as $tld => $entity)
{
if (!empty($entity))
{
list($server,) = explode('|', $entity, 2);
// if there are multiple TLD servers (pick the first one)
if (strpos($server, ',') !== FALSE)
{
$server = explode(',', $server);
$server = trim($server[0]);
}
$servers[strtolower($tld)] = strtolower($server);
}
}
// split the TLD from domain name
$_domain = explode('.', $domain);
$lst = count($_domain)-1;
$ext = $_domain[$lst];
if (!isset($servers[$ext]))
{
trigger_error('No matching nic server found!', E_USER_ERROR);
// http://www.nirsoft.net/whois-servers.txt
}
$nic_server = $servers[$ext];
}
else
{
$nic_server = strip_tags(trim($registrar));
}
// 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
{
trigger_error('Could not connect to '.$nic_server.'!', E_USER_ERROR);
}
return $output;
}
// findWhois($string) {}
}
if ($result = Domtooz::queryWhois('travisfont.com'))
{
echo '<pre>';
print_r($result);
}
#var_dump(Domtooz::checkTLD(Domtooz::explodeTLD('[email protected]')));