A simple PHP online port scanner

Source: Internet
Author: User
Keywords A simple PHP online port scanner
Tags php online

Author: Angel

Objective

PHP is a powerful web development language. The development of high efficiency, simple syntax, for the dynamic site tailored to enhance the object-oriented (to C + +, and Java to a point edge), unfortunately single-threaded (this is to life weaknesses, it is said that PHP is written in c\c++. ), can also use C, C + +, Java development of the middle tier, call COM, server maintenance is less difficult, fewer failures.

Since it is tailor-made for the dynamic website, it is doomed not to develop x-scan such a strong scanner, but if you want to achieve some simple functions, is more than enough.

Port scanning is our most commonly used casing method. If you're in a place like this, downloading a dedicated scanner is a hassle if you take advantage of the port scan provided by the existing Web service. That's really a lot to save.

Now let's look at the source code of this PHP port scanner I wrote:


$youip = $HTTP _server_vars["REMOTE_ADDR"]; Get the native IP address

$remoteip = $HTTP _post_vars[' Remoteip '); Get the IP address of the form submission

?>

Port on-line detection

if (!empty ($REMOTEIP)) {

Enter the IP address format if the form is not empty
function err () {

Die ("Sorry, this IP address is not valid

Click here to return ");


}

To define a prompt to submit an error IP
$ips =explode (".", $remoteip);

Use the. 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 first and last IP numbers are less than 1 or greater than 255, an error is indicated
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 numbers is less than 0 or greater than 255, an error is indicated
$closed = ' This port is currently in a closed state. Www.cncms.com ';

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

$close = "Off";

$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 '

);

Define the service name and status for each port by using an array after the IP format check
echo "

echo "

echo "


echo "

echo "

\ n "; \ n "; \ n "; \ n ";
IP you are scanning:

Color=red> ". $remoteip."

\ n ";

echo "


echo "

echo "


echo "


echo "


echo "


echo "

Output the displayed table
for ($i =0; $i < p="">

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

if (! $fp) {

echo "


} else {

echo "


}

}

Use the For statement to connect the remote host's associated port with the Fsockopen function and output the result
echo "


echo "

{


Align=center> ". $close."


Align=center> ". $open."

echo "

\ n "; \ n "; \ n "; \ n "; \ n "; \ n "; \ n "; < p=""> \ n "; < p=""> "; \ n ";
Port Service Test results Describe
". $port [$i]." ". $msg [$i]." ". $closed."
". $port [$i]." ". $msg [$i]." ". $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

}

End of probe
echo "

echo "

echo "


echo "

echo "";

echo "

\ n "; \ n "; \ n "; \ n ";
Your IP: ". $youip."
\ n ";

Display a form that submits an IP address if the form is empty
?>

copyright©2004 Security Angel TEAM[S4T]
All rights Reserved.

Postscript

This scanner is very simple. is to use an array to define the port related information, 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 a cost, in fact, write this code is to tell everyone, PHP and not only for the development of Dynamic Web site, but also for the network security field, often too much attention to the work of things, will ignore other aspects of the characteristics.

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.