-
- Downloads
- Use stream_socket_pair() to send fping results from child to parent process
Avoids infinite loop if child process fails to create the pipe file Avoids race condition resulting in fping not discovering IPs ```php while (!empty($threads)) { foreach ($threads as $index => $thread) { $child_pipe = "/tmp/pipe_" . $thread->getPid(); if (file_exists($child_pipe)) { // child thread failed to create this file $file_descriptor = fopen($child_pipe, "r"); $child_response = ""; while (!feof($file_descriptor)) { $child_response .= fread($file_descriptor, 8192); } $child_response = unserialize($child_response); $scan_subnets[$index]->discovered = $child_response; unlink($child_pipe); unset($threads[$index]); // This never runs = $threads[] can never be empty = inf loop } } } ``` ```php while (!empty($threads)) { foreach ($threads as $index => $thread) { $child_pipe = "/tmp/pipe_" . $thread->getPid(); if (file_exists($child_pipe)) { // Child thread has created this file. $file_descriptor = fopen($child_pipe, "r"); $child_response = ""; while (!feof($file_descriptor)) { // Child thread has not yet called fwrite() to send us the data. $child_response .= fread($file_descriptor, 8192); } $child_response = unserialize($child_response); // The response is blank "" $scan_subnets[$index]->discovered = $child_response; unlink($child_pipe); unset($threads[$index]); } } } ``` - Use join() to wait for child processes to exit instead of polling isAlive() in busy loop. - Run $thread->start() in try-catch blocks to avoid terminating scripts on errors. - Provide user feedback if we can't spawn a scanning thread. - Misc code cleanups
Showing
- functions/classes/class.Scan.php 27 additions, 24 deletionsfunctions/classes/class.Scan.php
- functions/classes/class.Thread.php 106 additions, 35 deletionsfunctions/classes/class.Thread.php
- functions/scan/subnet-scan-icmp-execute.php 39 additions, 64 deletionsfunctions/scan/subnet-scan-icmp-execute.php
- functions/scan/subnet-scan-telnet-execute.php 29 additions, 26 deletionsfunctions/scan/subnet-scan-telnet-execute.php
- functions/scripts/discoveryCheck.php 86 additions, 109 deletionsfunctions/scripts/discoveryCheck.php
- functions/scripts/pingCheck.php 133 additions, 150 deletionsfunctions/scripts/pingCheck.php
Loading
Please register or sign in to comment