1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php'; |
4
|
|
|
|
5
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
6
|
|
|
xoops_loadLanguage('main', $moduleDirName); |
7
|
|
|
|
8
|
|
|
class xWhois |
9
|
|
|
{ |
10
|
|
|
/* |
11
|
|
|
* Optional parameter for the server to be used for the lookup. |
12
|
|
|
* If this is not set, an appropriate whois server for the domain name |
13
|
|
|
* specified is automagically found by the Whois class. |
14
|
|
|
* @type string |
15
|
|
|
* @access public |
16
|
|
|
*/ |
17
|
|
|
public $whois_server; |
18
|
|
|
/* |
19
|
|
|
* The timeout, in seconds, for the lookup. Default is 30. |
20
|
|
|
* @type integer |
21
|
|
|
* @access public |
22
|
|
|
*/ |
23
|
|
|
public $timeout = 30; |
24
|
|
|
|
25
|
|
|
/* |
26
|
|
|
* Returns a string, with new-lines (\n) converted to non-breaking spaces (<BR>), |
27
|
|
|
* with details for the domain specified by $domain. |
28
|
|
|
* @access public |
29
|
|
|
* @param string $domain the domain to lookup, excluding http:// and www |
30
|
|
|
* @return string the results of the whois |
31
|
|
|
*/ |
32
|
|
|
public function lookup($domain) |
33
|
|
|
{ |
34
|
|
|
$result = ''; |
35
|
|
|
$parts = []; |
|
|
|
|
36
|
|
|
$host = ''; |
|
|
|
|
37
|
|
|
|
38
|
|
|
// .tv don't allow access to their whois |
39
|
|
|
if (false !== mb_strpos($domain, '.tv')) { |
40
|
|
|
//$result = "'.tv' domain names require_once you to have an account to do whois searches."; |
41
|
|
|
$result = "Please contact us regarding the $domain"; |
42
|
|
|
// New domains fix (half work, half don't) |
43
|
|
|
} elseif (false !== mb_strpos($domain, '.name') || false !== mb_strpos($domain, '.pro') > 0) { |
44
|
|
|
//$result = ".name,.pro require_once you to have an account to do whois searches."; |
45
|
|
|
$result = "Please contact us regarding $domain"; |
46
|
|
|
} else { |
47
|
|
|
if (empty($this->whois_server)) { |
48
|
|
|
$parts = explode('.', $domain); |
49
|
|
|
$testhost = $parts[count($parts) - 1]; |
50
|
|
|
$whoisserver = $testhost . '.whois-servers.net'; |
51
|
|
|
$this->host = gethostbyname($whoisserver); |
|
|
|
|
52
|
|
|
$this->host = gethostbyaddr($this->host); |
53
|
|
|
|
54
|
|
|
if ($this->host == $testhost) { |
55
|
|
|
$this->host = 'www.internic.net'; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$whoisSocket = fsockopen($this->host, 43, $errno, $errstr, $this->timeout); |
60
|
|
|
|
61
|
|
|
if (!$whoisSocket) { |
|
|
|
|
62
|
|
|
$result = STATS_DNSLOOKUP_ERROR . '<br>' . $errno . ' - ' . $errstr . '<br>'; |
63
|
|
|
} else { |
64
|
|
|
fwrite($whoisSocket, $domain . "\015\012"); |
65
|
|
|
while (!feof($whoisSocket)) { |
66
|
|
|
$result .= fgets($whoisSocket, 128) . '<br>'; |
67
|
|
|
} |
68
|
|
|
fclose($whoisSocket); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function reverselookup($ip) |
76
|
|
|
{ |
77
|
|
|
// using the arin database cgi...have to keep an eye on things to make sure it works long term! |
78
|
|
|
$fullurl = "http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip"; |
79
|
|
|
|
80
|
|
|
$url = parse_url($fullurl); |
81
|
|
|
|
82
|
|
|
if (!in_array($url['scheme'], ['', 'http'])) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$fp = fsockopen($url['host'], ($url['port'] > 0 ? $url['port'] : 80), $errno, $errstr, $this->timeout); |
87
|
|
|
if (!$fp) { |
|
|
|
|
88
|
|
|
$d = STATS_REVERSELOOKUP_ERROR . '<br>' . $errno . ' - ' . $errstr . '<br>'; |
89
|
|
|
} else { |
90
|
|
|
fwrite($fp, 'GET /' . $url['path'] . ($url['query'] ? '?' . $url['query'] : '') . " HTTP/1.0\r\nHost: " . $url['host'] . "\r\n\r\n"); |
91
|
|
|
$d = ''; |
92
|
|
|
while (!feof($fp)) { |
93
|
|
|
$d .= fgets($fp, 2048); |
94
|
|
|
} |
95
|
|
|
fclose($fp); |
96
|
|
|
|
97
|
|
|
$d = mb_stristr($d, 'Search results for: '); |
98
|
|
|
$d = str_replace('cgi-bin/whois.pl?queryinput=N%20!%20', 'modules/statistics/admin/index.php?op=reverseip&iplookup=', $d); |
99
|
|
|
$d = str_replace('cgi-bin/whois.pl?queryinput=P%20!%20', 'modules/statistics/admin/index.php?op=reverseip&iplookup=', $d); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $d; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|