Dahne Training: PHP online port Scanner

Source: Internet
Author: User
Tags php online

Dahne Training: PHP online port Scanner

[Source] Dahne [edit] Dahne [Time]2012-12-21

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

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 cc++. ), 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

?>

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. ‘;

$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 "n";

echo "n";

echo "The IP You scanned:

Color=red> ". $remoteip." n ";

echo "

n ";

echo "n";

echo "n";

echo "n";

echo "Port n";

echo "Service n";

echo "test result n";

echo "Description n";

echo "

n ";

Output the displayed table

for ($i =0; $i

{

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

if (! $fp) {

echo "". $port [$i]. "".  $msg [$i]. " Align=center> ". $close." ". $closed. "

n ";

} else {

echo "". $port [$i]. "".  $msg [$i]. " Align=center> ". $open." ". $opened. "

";

}

}

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

echo "n";

echo "continue scanning >>>n";

echo "

echo "

n ";

echo "n";

echo "n";

echo "copyright©2004 Security

Angel TEAM[S4T] All rights RESERVED.N ";

echo "

n ";

echo "n";

echo "

n ";

echo "n";

echo "n";

Exit

}

End of probe

echo "n";

echo "n";

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

echo "

n ";

echo "

n ";

echo "n";

echo "n";

echo "n";

echo "

n ";

echo "

";

echo "n";

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

?>

copyright©2004 Security Angel TEAM[S4T]

All rights Reserved.

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.

Dahne Training: PHP online port Scanner

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.