1. Preface
This paper uses the Fsockopen () function to write a simple-function port scanner.
2. Key Technologies
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 is thrown. All you need to add @ $result = $fp? ' <span style= ' color:red > Open </span> ': ' <span style= ' color:red ' > Close </span> '; Echo ' <td> '. $result. ' </td> '; Echo ' </tr> ';}
3, the code is as follows
<! DOCTYPE html>