-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcheck-ports.php
More file actions
38 lines (32 loc) · 932 Bytes
/
check-ports.php
File metadata and controls
38 lines (32 loc) · 932 Bytes
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
<?php
/**
* Plugin Name: test-open-tcp-ports.php
* Description: Original created to test if ports are open outbound on hosting providers to be able to send tranational email
* Version: 1.0.0
* Status: Complete
* Type: mu-plugin
*/
function testPorts($host, $ports, $timeout) {
$openPorts = [];
foreach ($ports as $port) {
$errno = 0;
$errstr = '';
$connection = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ($connection) {
$openPorts[] = $port;
fclose($connection);
}
}
return $openPorts;
}
$host = 'hostname';
$ports = [20, 21, 22, 23, 25, 53, 80, 110, 143, 443, 8080]; // List of ports to check
$timeout = 5;
$openPorts = testPorts($host, $ports, $timeout);
if (!empty($openPorts)) {
echo "Open ports on $host:\n";
echo implode(', ', $openPorts);
} else {
echo "No open ports found on $host.";
}
?>