What are the potential security risks of using fsockopen in PHP for scanning subnets?

Using fsockopen in PHP for scanning subnets can pose security risks such as potential network vulnerabilities, denial of service attacks, and exposing sensitive information. To mitigate these risks, it is important to validate user input, limit the number of connections, and properly handle errors.

<?php
$ip = '192.168.1.1';
$port = 80;
$timeout = 1;

$socket = @fsockopen($ip, $port, $errno, $errstr, $timeout);

if ($socket) {
    echo "Port $port is open on $ip";
    fclose($socket);
} else {
    echo "Port $port is closed on $ip";
}
?>