Status checker for hundreds IP addresses

前端 未结 10 1579
长发绾君心
长发绾君心 2021-01-02 01:52

I wonder how to make a status checker, checking about 500 addresses in a few minutes? (it\'ll check a certain port if its listening).

But I care about the performanc

10条回答
  •  执念已碎
    2021-01-02 02:14

    C# would be a better option as you can use threads to speed up the process.

    In PHP, you can essentially check if a TCP port is open by using fsockopen().

    $host = 'example.com';
    $port = 80;
    $timeout = 30;
    
    $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
    if (!$fp) {
        echo "Port $port appears to be closed on $host  Reason: $errno: $errstr.\n";
    } else {
        echo "Port $port is open on $host\n";
        fclose($fp);
    }
    

    As kz26 said, you could also get something like nmap to check the ports on a bunch of hosts and use php to call it and process the results as well.

提交回复
热议问题