Home > Backend Development > PHP Tutorial > A simple php online port scanner_PHP tutorial

A simple php online port scanner_PHP tutorial

WBOY
Release: 2016-07-21 14:52:25
Original
1005 people have browsed it

PHP is a powerful web development language. It has high development efficiency and simple syntax. It is tailor-made for dynamic websites and is more object-oriented (closer to C++ and has some connections with JAVA). Unfortunately, it is single-threaded (this is its fatal weakness. It is said that PHP is written in CC++.), You can also use C, C++, and JAVA to develop the middle layer and call COM. The server maintenance is easy and there are few failures.

Since it is tailor-made for dynamic websites, it is destined not to develop a powerful scanner like X-scan, but if you want to implement some simple functions, it is more than enough.

Port scanning is our most commonly used means of checking. If you are in a place like an Internet cafe, it will be more troublesome to download a special scanner. If you use the port scanning provided by the 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:

Code:


//Codz by angel

$youip=$HTTP_SERVER_VARS["REMOTE_ADDR"]; // Get the local IP address
$remoteip=$HTTP_POST_VARS['remoteip']; // Get the IP address of form submission
?>


Security Angel——Port Online Detection





if (!empty($remoteip)){
// If the form is not empty, enter the IP address format judgment

function err() {
​​​​​die("Sorry, the IP address is illegal

Click here to return");
}
// Define the prompt message for submitting the wrong IP

$ips=explode(".",$remoteip);
// Split the IP address with .

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 less than 1 or greater than 255, an error will be 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 the second and third IP segments is less than 0 or greater than 255, an error will be prompted

$closed='This port is currently closed. ';
$opened='This port is currently open! ';
$close="Close";
$open="Open";
$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'
); 
// After checking the IP format, use an array to define the service name and status corresponding to each port

echo "

n";
echo "n";
echo "n";
echo "n";
echo "
The IP you scanned: color=red>".$remoteip."
n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
// Output the displayed table

for($i=0;$i {
$fp = @fsockopen($remoteip, $port[$i], &$errno, &$errstr, 1);
if (!$fp) {
echo "
n";
} else {
echo "";
}
}
// Use the for statement to connect to the relevant ports of the remote host using the fsockopen function and output the results

echo "n";
echo " echo "
portserviceDetection resultsdescription
".$port[$i]."".$msg[$i]." align=center>".$close."".$closed."
".$port[$i]."".$msg[$i]."align=center>".$open."".$opened."
n";
echo "Continue scanning>>>
n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "
Copyright © 2004 Security Angel Team[S4T] All Rights Reserved.
n";
echo "
n";
echo "n";
echo "n";
exit;
}
// Detection ends

echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "n";
echo "";
echo "
Your IP:".$youip."
n";
echo "n";
echo "n";
echo "
n";
// If the form is empty, display the form to submit the IP address

?>





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



Postscript

This scanner is very simple. An array is used to define the relevant information of the port. The principle is to use the fsockopen function to connect. If it can be connected, it means that the port is open, otherwise it is closed.

The biggest disadvantage is that PHP is single-threaded, so the speed will be very slow. This is at the expense of convenience and simplicity. In fact, the person who wrote this code wants to tell everyone that PHP is not only used for the development of dynamic websites, it can also be used In the field of network security, people often pay too much attention to the original work of things and ignore the characteristics of other aspects.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371606.htmlTechArticlePHP is a powerful web development language. It has high development efficiency and simple syntax. It is tailor-made for dynamic websites and is more object-oriented (closer to C++ and has some connections with JAVA). Unfortunately, it is single-threaded...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template