This paper uses the Fsockopen () function to write a simple-function port scanner. The port number of this instance is fixed, through an array of traversal, using the Fsockopen () function connection, if the connection is successful, the port is open, otherwise it is closed.
The core code is as follows:
foreach ($port as $key = + $value) {echo ' <tr> '; Echo ' <td> '. $key. ' </td> '; Echo ' <td> '. $value. ' </td> '; Echo ' <td> '. $msg [$key]. ' </td> '; $errno and $ERRSTR are basically not available here, just to set the timeout to prevent the request from timing out $fp = @fsockopen ($ip, $value, $errno, $ERRSTR, 1);//If the host (hostname) is inaccessible, A warning level (e_warning) error message will be thrown. All you need to add @ $result = $fp? ' <span > Open </span> ': ' <span > Close </span> '; Echo ' <td> '. $result. ' </td> '; Echo ' </tr> ';}
<! DOCTYPE html>
Because lazy, the page and the results are written together, the layout will be put.
Introduction to main functions
Fsockopen
Creates a connection based on a host name, returns a resource object successfully, fails to return false, and a warning is thrown when the host is unavailable