Use the fsockopen () function to open the port scanner instance,
1. Preface
This article uses the fsockopen () function to compile a simple port scanner.
2. Key Technologies
The port number of this instance is fixed. By traversing the array, use the fsockopen () function to connect. If the connection is successful, the port is open; otherwise, the port 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 unavailable here, just to set timeout and prevent request timeout $ fp = @ fsockopen ($ ip, $ value, $ errno, $ errstr, 1); // if the host (hostname) is inaccessible, an error message with the warning level (E_WARNING) will be thrown. @ $ Result = $ fp? '<Span> enabled </span>': '<span> disabled </span>'; echo '<td> '. $ result. '</td>'; echo '</tr> ';}
3. The Code is as follows:
<! DOCTYPE html>
Because of laziness, the pages and results are written together, and the layout will be changed.
4. Introduction to main functions
4.1. fsockopen
Creates a connection based on a host name. If a connection succeeds, a resource object is returned. If the connection fails, false is returned. If the host is unavailable, a warning is thrown.
Http://php.net/manual/en/function.fsockopen.php for details
The above example of using the fsockopen () function to open the port scanner is all the content that I have shared with you. I hope to give you a reference, and I hope you can provide more support for the customer's house.