PHP is a powerful web development language. The development of high efficiency, simple syntax, for dynamic Web sites tailored to strengthen the object-oriented (to C + +, and Java to build a point), but a single thread (this is the Achilles ' heel, it is said that PHP is written with c\c++.) ), can also use C, C + +, Java development of the middle tier, call COM, server maintenance difficult, less trouble.
Since it is tailor-made for dynamic Web sites, it is doomed not to develop such a x-scan scanner, but if you want to achieve a number of simple functions, or more than sufficient.
Port scanning is our most common method of casing. If you're in a place like this, downloading a specialized scanner is a hassle if you use an existing Web service-provided port scan. That's really a lot to save.
Let's take a look at the source code of this PHP port scanner I wrote:
$youip = $HTTP _server_vars["REMOTE_ADDR"]; Get native IP address
$remoteip = $HTTP _post_vars[' Remoteip ']; Get the IP address of the form submission
?>
<title> Security Angel--port on-line 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>
<body>
<center>
<?php
if (!empty ($REMOTEIP)) {
The decision to enter the IP address format if the form is not empty
function err () {
Die ("Sorry, the IP address is not legal <p><a Href=javascript:history.back (1) > Click here to return </a>");
}
To define a message that submits error IP
$ips =explode (".", $remoteip);
Use. Split IP Address
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 is less than 1 or greater than 255, an error is prompted
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 IP in the second and third segments is less than 0 or greater than 255, an error is prompted
$closed = ' This port is currently off. ';
$opened = ' <font color=red> This port is currently open! </font> ';
$close = "Close";
$open = "<font color=red> open </font>";
$port =array (21,23,25,79,80,110,135,137,138,139,143,443,445,1433,3306,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 '
);
Define the service name and status of each port by using an array after checking IP format
This scanner is very simple. is to use an array to define the relevant information of the port, the principle is to use the Fsockopen function connection, if you can connect, it means that the port is open, otherwise it is closed.
The biggest drawback is that PHP is single-threaded, so the speed will be very slow, this is convenient, simple as the price, in fact, write this code is to tell you, PHP is not only for dynamic Web site development, can also be used in the field of network security, often too much attention to the work of things, will ignore other aspects of the characteristics.
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.