PHP fsockopen () Open port scanner detailed

Source: Internet
Author: User
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

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.