Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
93 lines (90 loc) · 2.61 KB
/
Copy pathindex.php
File metadata and controls
93 lines (90 loc) · 2.61 KB
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
<?
internet_check();
http_check('https://www.example.com/admin/login', 'Username');
tcp_check('example.com', '3389');
dns_check('example.com.', '12.34.56.78');
function internet_check()
{
set_error_handler('handleError');
try {
fsockopen("www.google.ee", 80);
} catch(Exception $e) {
$fp = fopen('log', 'a');
fputs($fp, date('[Y-m-d H:i:s] ').$e->getMessage()."\n");
fclose($fp);
die();
}
}
function handleError($errno, $errstr, $errfile, $errline, array $errcontext)
{
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException(date('m.d H:i '). $errstr, 0, $errno, $errfile, $errline);
}
function dns_check($host, $ip)
{
set_error_handler('handleError');
$resolved_ip = gethostbyname($host);
if( $resolved_ip == $host )
echo "Hosti $host IP leidmine nurjus\n";
elseif( $resolved_ip != $ip )
echo "Hosti $host IP kontrollimine andis '$ip' asemel tulemuseks hoopis '$resolved_ip'\n";
}
function http_check($url, $find) {
set_error_handler('handleError');
$url_array = parse_url($url);
$host = isset($url_array['host']) ? $url_array['host'] : $_SERVER['SERVER_NAME'];
$path = isset($url_array['path']) ? $url_array['path'] : '/';
if( !isset($url_array['scheme']) or $url_array['scheme'] == 'http' ) {
$port = isset($url_array['port']) ? $url_array['port'] : 80;
try {
$fp = fsockopen($host, $port, $errno, $errstr, 10) or die("Ei saanud avada $host\m");
} catch (Exception $e){
echo date('H:i') . " URL-i $url kontrollimine nurjus:\n";
}
}
elseif( $url_array['scheme'] == 'https' ) {
$port = isset($url_array['port']) ? $url_array['port'] : 443;
try {
$fp = fsockopen("ssl://$host", $port, $errno, $errstr, 10) or die("Ei saanud avada $host\n");
} catch (Exception $e){
echo "Testing $url failed:\n";
}
}
if (!isset($fp)) {
echo "$errstr ($errno)\n";
} else {
$header = "GET $path HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "Connection: close\r\n\r\n";
try {
fputs($fp, $header);
} catch (Exception $e){
echo "Testing TCP $host:$port failed: $errstr\n";
}
$str = '';
while (!feof($fp)) {
$str .= fgets($fp);
}
#print_r($str);
fclose($fp);
if(strpos($str, $find) === false)
{
$short_url = str_replace('https://', '', $url);
$short_url = str_replace('http://', '', $short_url);
echo "$short_url != '$find'. Sisu: $str\n";
}
}
}
function tcp_check($host, $port) {
set_error_handler('handleError');
try {
$fp = fsockopen($host, $port, $errno, $errstr, 1);
fclose($fp);
} catch (Exception $e){
echo "Testing TCP $host:$port failed: $errstr\n";
}
return true;
}