Introduction: this is a simple PHP online port scanner details page, introduced and PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 323731 'rolling = 'no'>
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.
Next let's take a look at the PHP port scanner I wrote.Source code:
<? PHP
$ Youip = $ http_server_vars ["remote_addr"]; // obtain the local IP Address
$ Remoteip = $ http_post_vars ['remoteip']; // obtain the IP address submitted in the form
?>
<HTML>
<Head>
<Title> online port detection </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style type = "text/CSS">
<! --
Body {font-size: 12px; font-family: verdana; color: #000000;
}
TD {
Font-size: 12px;
Font-family: verdana;
Color: #000000;
Line-Height: 14px;
}
. Style1 {color: # ffffff}
-->
</Style>
</Head>
<Body>
<Center>
<? PHP
If (! Empty ($ remoteip )){
// Judge the IP address format if the form is not empty
Function err (){
Die ("sorry, this IP address is illegal <p> <a href = javascript: history. Back (1)> click here to return </a> ");
}
// 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 = '<font color = Red> This port is currently open! </Font> ';
$ Close = "close ";
$ Open = "<font color = Red> open </font> ";
$ 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 "<Table border = 0 cellpadding = 15 cellspacing = 0> \ n ";
Echo "<tr> \ n ";
Echo "<TD align = center> <strong> ip address you scanned: <font
Color = Red> ". $ remoteip." </font> </strong> </TD> \ n ";
Echo "</tr> \ n ";
Echo "</table> \ n ";
Echo "<Table cellpadding = 5 cellspacing = 1 bgcolor = #636194> \ n ";
Echo "<tr bgcolor = #7371a5 align = center> \ n ";
Echo "<TD> <SPAN class = style1> port </span> </TD> \ n ";
Echo "<TD> <SPAN class = style1> service </span> </TD> \ n ";
Echo "<TD> <SPAN class = style1> detection result </span> </TD> \ n ";
Echo "<TD> <SPAN class = style1> description </span> </TD> \ n ";
Echo "</tr> \ n ";
// Output the displayed table
For ($ I = 0; $ I <sizeof ($ port); $ I)
{
$ Fp = @ fsockopen ($ remoteip, $ port [$ I], & $ errno, & $ errstr, 1 );
If (! $ FP ){
Echo "<tr bgcolor = # ffffff> <TD align = center> ". $ port [$ I]. "</TD> <TD> ". $ MSG [$ I]. "</TD> <TD
Align = center> ". $ close." </TD> <TD> ". $ closed." </TD> </tr> \ n ";
} Else {
Echo "<tr bgcolor = # f4f7f9> <TD align = center> ". $ port [$ I]. "</TD> <TD> ". $ MSG [$ I]. "</TD> <TD
Align = center> ". $ open." </TD> <TD> ". $ opened." </TD> </tr> ";
}
}
// Use the for statement to connect the port of the remote host using the fsockopen function and output the result.
Echo "<tr> <TD colspan = 4 align = center> \ n ";
Echo "<a href = portscan. php> <font color = # ffffff> Continue scanning >></font> </a> </TD> \ n ";
Echo "</tr \ n ";
Echo "</table> \ n ";
Echo "<Table cellspacing = 0 cellpadding = 10 width = 100% border = 0> \ n ";
Echo "<tr> \ n ";
Echo "<TD align = center> <B> copyright & copy; 2004 Security
Angel team [s4t] All Rights Reserved. </B> </TD> \ n ";
Echo "</tr> \ n ";
Echo "</table> \ n ";
Echo "</center> \ n ";
Echo "</body> \ n ";
Echo "
Exit;
}
// Detection complete
Echo "<Table border = 0 cellpadding = 15 cellspacing = 0> \ n ";
Echo "<tr> \ n ";
Echo "<TD align = center> <strong> your IP address: <font color = Red> ". $ youip. "</font> </strong> </TD> \ n ";
Echo "</tr> \ n ";
Echo "<form method = post action = portscan. php> \ n ";
Echo "<tr> <TD> \ n ";
Echo "<input type = text name = remoteip size = 12> \ n ";
Echo "<input type = submit value = scan name = scan> \ n ";
Echo "</TD> </tr> \ n ";
Echo "</form> ";
Echo "</table> \ n ";
// If the form is empty, the IP address submission form is displayed.
?>
<Table cellspacing = 0 cellpadding = 10 width = "100%" border = 0>
<Tr>
<TD align = center> <B> copyright & copy; 2004 Security Angel team [s4t]
All rights reserved. </B> </TD>
</Tr>
</Table>
</Center>
</Body>
</Html>
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 easy to use and simple as the cost.CodeI want to tell you that PHP is not only used for dynamic website development, but also for the network security field. If you pay too much attention to your work, you will ignore other features.
More articles on "A simple PHP online port scanner"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/323731.html pageno: 16.