Use the fsockopen () function to open the port scanner instance,

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.