A simple php online Port scanner _ PHP

Source: Internet
Author: User
Tags php online
Author: angel preface PHP is a powerful Web development language. High development efficiency, simple syntax, tailored for dynamic websites, and enhanced object-oriented (moving closer to C and setting up edges with JAVA). Unfortunately, a single thread (this is a weakness of life, it is said that PHP is written in CC .), It can also use the C, C, and JAVA development middle layers to call COM. it is difficult to maintain servers and has fewer faults. author: angel

Preface

PHP is a powerful Web development language. High development efficiency, simple syntax, tailored for dynamic websites, and enhanced object-oriented (moving closer to C and setting up edges with JAVA). Unfortunately, a single thread (this is a weakness of life, it is said that PHP is written in C \ C .), It can also use the C, C, and JAVA development middle layers to call COM. the server is less difficult to maintain and has fewer faults.

Since it is tailored for dynamic websites, it is doomed that super scanners such as X-scan cannot be developed. However, if you want to implement some simple functions, it is more than enough.

Port scanning is our most common method of stepping on. It is troublesome to download a dedicated scanner in a place like an Internet cafe. if you use a port scan provided by an existing Web service. That really saves a lot of trouble.

Let's take a look at the source code of the PHP port scanner I wrote:


$ Youip = $ HTTP_SERVER_VARS ["REMOTE_ADDR"]; // Obtain the local IP address

$ Remoteip = $ HTTP_POST_VARS ['remoteip']; // obtain the IP address submitted in the form

?>

Online Port detection


If (! Empty ($ remoteip )){

// Judge the IP address format if the form is not empty
Function err (){

Die ("Sorry, this IP address is illegal

Click here to return ");


}

// Defines the prompt message for an incorrect IP address submission.
$ Ips = explode (".", $ remoteip );

// Use. to separate IP addresses
If (intval ($ ips [0]) <1 or intval ($ ips [0])> 255 or intval ($ ips [3]) <1
Or intval ($ ips [3]> 255) err ();

// If the number of the first and last IP segments is smaller than 1 or greater than 255, an error is returned.
If (intval ($ ips [1]) <0 or intval ($ ips [1])> 255 or intval ($ ips [2]) <0
Or intval ($ ips [2]> 255) err ();

// If the number of the second and third IP addresses is less than 0 or greater than 255, an error is returned.
$ Closed = 'this port is currently closed. Www.knowsky.com ';

$ Opened = 'This port is currently open! ';

$ Close = "close ";

$ Open = "open ";

$ Port = array (80,110,135,137,138,139,143,443,445,143, 3389 );


$ Msg = array (

'Ftp ',

'Telnet ',

'Smtp ',

'Finger ',

'Http ',

'Pop3 ',

'Location service ',

'Netbios-NS ',

'Netbios-DGM ',

'Netbios-ssn ',

'Imap ',

'Https ',

'Microsoft-DS ',

'Mssql ',

'Mysql ',

'Terminal' Services'

);

// After checking the IP format, use an array to define the service name and status of each port.
Echo"

Echo"

Echo"


Echo"

Echo"

\ N "; \ N "; \ N "; \ N ";
IP address you scanned:

Color = red> ". $ remoteip ."

\ N ";

Echo"


Echo"

Echo"


Echo"


Echo"


Echo"


Echo"

// Output the displayed table
For ($ I = 0; $ I

$ Fp = @ fsockopen ($ remoteip, $ port [$ I], & $ errno, & $ errstr, 1 );

If (! $ Fp ){

Echo"


} Else {

Echo"


}

}

// Use the for statement to connect the port of the remote host using the fsockopen function and output the result.
Echo"


Echo"

{

Echo"

\ N "; \ N "; \ N "; \ N "; \ N "; \ N "; \ N "; \ N "; "; \ N ";
PortServiceDetection resultDescription
". $ Port [$ I]." ". $ Msg [$ I]."


Align = center> ". $ close ."

". $ Closed ."
". $ Port [$ I]." ". $ Msg [$ I]."


Align = center> ". $ open ."

". $ Opened ."
\ N ";

Echo "continue scanning >>>

\ N ";

Echo"


Echo"

Echo"

Echo"

Echo"

\ N "; \ N "; \ N "; \ N ";
Copyright©2004 Security
Angel Team [S4T] All Rights Reserved.
\ N ";

Echo"

\ N ";

Echo"\ N ";

Echo"\ N ";

Exit;

}

// Detection complete
Echo"

Echo"

Echo"


Echo"

Echo "";

Echo"

\ N "; \ N "; \ N "; \ N ";
Your IP address: ". $ youip ."
\ N ";

// If the form is empty, the IP address submission form is displayed.
?>


Copyright©2004 Security Angel Team [S4T]
All Rights Reserved.

Postscript

This scanner is simple. An array is used to define the port information. The principle is to use the fsockopen function to connect. if the port can be connected, the port is opened. Otherwise, the port is closed.

The biggest drawback is that PHP is a single thread, so the speed will be very slow. it is convenient and simple at the cost. In fact, what I want to write this code is to tell you, PHP is not only used for the development of dynamic websites, but also for the network security field. if you pay too much attention to your work, you will ignore other features.

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.