-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkdomain.php
192 lines (167 loc) · 7.55 KB
/
checkdomain.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/php
<?php
### require local whois or jwhois command ###
date_default_timezone_set("Asia/Shanghai");
if (count($argv) != 2) {
echo "Usage: " . $argv[0] . " <Domain Or DomainList[domain1,domain2] Or ListFile]>\n";
exit;
}
$domain_input = $argv[1];
$check_output = array();
$array_remaining_date = array();
$i = 0;
$id = 1;
$config_filter_format = array("Updated Date", "Creation Date", "Creation date", "Created On",
"Expiration Date", "Registrant Organization",
"Record expires", "Record created",
"Registration Date", "Registrant:",
"Registry Expiry Date", "Domain Name Commencement Date",
"Expiry", "Expiry Date",
"Owner", "Company name",
"Name Server", "NS 1", "Domain servers in listed order", "Name Servers Information"
);
$config_convert_format = array("Creation Date" => "Registration Date", "Creation date" => "Registration Date",
"Created On" => "Registration Date",
"Domain Name Commencement Date" => "Registration Date",
"Record created" => "Registration Date",
"Registrant" => "Registrant Organization", "Expiry Date" => "Expiration Date",
"Expiry" => "Expiration Date",
"Owner" => "Registrant Organization", "Company name" => "Registrant Organization",
"NS 1" => "Name Server", "Domain servers in listed order" => "Name Server",
"Name Servers Information" => "Name Server",
"Record expires" => "Expiration Date",
"Registry Expiry Date" => "Expiration Date", "Registrar Registration Expiration Date" => "Expiration Date");
$config_expiration_format = array("Expiration Date", "Registry Expiry Date", "Registrar Registration Expiration Date", "Expiry");
$config_output_format = array("Expiration Date", "Registration Date", "Name Server", "Registrant Organization");
$is_echo_msg = "yes"; // yes or no
$sleep_time = 2; // sleep time, Default: 1 second
### require local MTA ###
$is_send_mail = "no"; // yes or no
$mail_adminname = "DomainCheck";
$mail_adminmail = ""; // email: name@domain
$mail_noreply = ""; // email
$mail_to = ""; // email
$mail_subject = "Domain CheckList";
if (is_file($domain_input)) {
$domains = file($domain_input);
} else {
$domains = explode(",", $domain_input);
}
foreach ($domains AS $domain) {
$domain = trim($domain);
check_whois($domain);
sleep($sleep_time);
}
$message = "\n";
$message_mail = "<br>";
ksort($array_remaining_date, SORT_NUMERIC);
foreach ($array_remaining_date AS $k => $v) {
foreach ($v AS $kk => $vv) {
if ($i++ >= 5) {
break;
}
if ($i == 1) {
$mail_subject = $mail_subject . " [" . $check_output[$vv]["remaining_date"] . "]";
}
$message .= $vv . " 域名注册将在 " . $check_output[$vv]["remaining_date"] . " 后过期\n";
$message_mail .= $vv . " 域名注册将在 " . $check_output[$vv]["remaining_date"] . " 后过期<br>";
}
}
$message .= "\n\n";
$message_mail .= "<br><br>\n";
$message .= " | 编号 | 域名 | 剩余时间 | 过期时间 | 注册时间 | 域名服务商 | 注册主体 |\n";
$message_mail .= ' <table width="1100" border="1" cellpadding="2" cellspacing="0" bordercolorlight="#000000" bordercolordark="#FFFFFF" bgcolor="#FFFFEE">
<tr><th>编号</th><th>域名</th><th>剩余时间</th><th>过期时间</th><th>注册时间</th><th>域名服务商</th><th>注册主体</th></tr>';
foreach ($domains AS $domain) {
$domain = trim($domain);
if (!isset($check_output[$domain]["remaining_date"])) {
$check_output[$domain]["remaining_date"] = " NULL ";
}
if ($check_output[$domain]["remaining_date"] <= 90) {
$bgcolor = "bgcolor='red'";
} else {
$bgcolor = "";
}
$message .= " | $id | " . $domain . " \t| " . $check_output[$domain]["remaining_date"] . " | ";
$message_mail .= "<tr $bgcolor><td>" . $id++ . "</td><td>" . $domain . "</td><td>" . $check_output[$domain]["remaining_date"] . "</td>";
foreach ($config_output_format AS $key) {
if (!isset($check_output[$domain][$key])) {
$message .= " NULL \t| ";
$message_mail .= " <td> NULL </td> ";
if (!isset($message_unknow_domain[$domain])) {
$message_unknow_domain[$domain] = $domain . " 域名过期时间未知<br>\n";
}
} else {
$message .= $check_output[$domain][$key] . " \t| ";
$message_mail .= "<td>" . $check_output[$domain][$key] . " </td>";
}
}
$message .= "\n";
$message_mail .= "</tr>\n";
}
$message .= "\n";
$message_mail .= "</table><br><br>\n";
$message = join("", $message_unknow_domain) . $message;
$message_mail = join("", $message_unknow_domain) . $message_mail;
if ($is_echo_msg == "yes") {
echo $message;
}
if ($is_send_mail == "yes") {
send_mail($mail_to, $mail_subject, $message_mail);
}
function send_mail($mail_to, $mail_subject, $message) {
global $mail_adminname, $mail_noreply, $mail_adminmail;
$subject = "=?utf-8?B?".base64_encode($mail_subject)."?=";
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\n";
$headers .= "From: =?utf-8?B?".base64_encode($mail_adminname)."?= <" . $mail_noreply . ">" . "\n";
$headers .= 'Cc : '. $mail_adminmail . "\n";
$headers .= 'References: <'.date("Ym").'@domaincheck>' . "\n";
$headers .= "\n\r";
if ($mail_to != "" and $message != "") {
mail($mail_to, $subject, $message, $headers);
}
}
function check_whois ($domain) {
global $config_filter_format, $check_output, $config_expiration_format, $config_convert_format, $array_remaining_date, $sleep_time;
$config_match = implode('|', $config_filter_format);
if (!@exec("whois $domain", $result)) {
sleep($sleep_time);
@exec("whois $domain", $result);
sleep($sleep_time);
@exec("whois $domain", $result);
}
$result_text = join("\n", $result);
$result_text = preg_replace("/:\n+/" , ":", $result_text);
$result = preg_split("/\n/", $result_text);
foreach ($result AS $value) {
if (preg_match("/(:| on )/", $value) and preg_match("/^\s+$config_match/", $value)) {
$split_value = preg_split("/(:| on )/", $value);
$k = trim($split_value[0]);
$v = trim($split_value[1]);
if (isset($config_convert_format[$k])) {
$k = $config_convert_format[$k];
}
if (isset($check_output[$domain][$k])) {
continue;
}
if (preg_match("/Date/i", $k)) {
$v = preg_replace("/\s+\w+\s*$/", "", $v);
$v = preg_replace("/T\d+$/", "", $v);
$v = preg_replace("/\//", "-", $v);
$v = preg_replace("/\s+\((\w|-)*\)$/", "", $v); // because .tw
$v = date("Y-m-d", strtotime($v));
}
if (in_array($k, $config_expiration_format)) {
$remaining_date = intval((strtotime($v) - time()) / 86400) . "天";
if ($remaining_date < -100) {
continue;
}
$check_output[$domain]["remaining_date"] = $remaining_date;
$array_remaining_date[$remaining_date][$domain] = $domain;
}
$check_output[$domain][$k] = $v;
}
}
}
?>