forked from crapos/piavpn-portforward
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpc.php
37 lines (35 loc) · 909 Bytes
/
pc.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
<?
$host="udp://".$_SERVER['REMOTE_ADDR'];
$timeout=1;
// deal with exceptions thrown by fsockopen
$handle = @fsockopen(
$host,
$_GET["p"],
$errno,
$errstr,
2
);
if (!$handle) {
// echo "$errno : $errstr <br/>";
echo "Error";
return;
}
// TODO: verify that socket_set_timeout() is required
socket_set_timeout($handle, $timeout);
$write = fwrite($handle, "\x00");
if (!$write) {
echo "Closed";
return;
}
$startTime = time();
$header = fread($handle, 1);
$endTime = time();
$timeDiff = $endTime - $startTime;
if ($timeDiff >= $timeout) {
fclose($handle);
echo "Open";
} else {
fclose($handle);
echo "Closed";
}
?>