PHP: Port scanner

Translation of the original in Catalan. Read it in: CatalàCastellano

While poking around Linux Security I found the reference to a very curious document, it's about implementing a port scanner in PHP, in fact the document explains how from a port scanner written in C you can extract the code in PHP.

The whole article is on the PHPWizard website and it's titled: "Securing Servers With PHP" but I don't have the link at hand.

In case someone still hasn't seen what this can let us do, well think that we could run a port scan on a site

from the IP of any PHP server without showing our IP, it would be like having an online port scanner that doesn't reveal our identity ;)

So in case someone needs the code urgently here it goes:

<br /?

// port.php,v 1.3 2001/08/21 19:54:19 barce Exp

//

// A basic port scanner written in PHP.

//

/****************************************

* *

* $min is the first port scanned *

* $max is the last port scanned *

* *

****************************************/

$timeout = 1; // Use a timeout with a short duration

if ($pressed)

{

set_time_limit(0);

echo "Scanning $target" . "...

n"; flush();

for (i=i = min; i &lt;= max; $i++)

{

/*********************************************************

* *

* Open a Socket Connection with fsockopen *

* *

*********************************************************/

handle=fsockopen(handle = fsockopen(target, i,i, errno, errstr,errstr, timeout);

/*********************************************************

* *

* Test connection to see if port is open *

* *

*********************************************************/

if (!$handle)

{

echo "No connection at port $i

n"; flush();

} else {

echo "Open port at $i

n"; flush();

fclose($handle);

}

}

} else {

/*********************************************************

* *

* A form to ask user for a host to target *

* *

*********************************************************/

echo "

n";

}

?>

3 comments

Comments from the old blog, as they were written. Comments are closed.

  1. daph

    ja veig q no perds el temps a VLC i a més a més et conectas quan
    jo em conecto...clar per a seguir la costum, apa q vagi bé amb el codi
    qui el volgui utilitzar ;)

  2. FrantIc

    escaner de ports?? i ke cony he fet jo al projecte?? fsockopen, la gran funcio.
    Cal dir ke al codi ke has penjat es tracta dun escaner de ports tcp, per ferlu
    de udp cal canviar els parametres de la funcio d'obertura de sockets.

    Per aixo mu curru?? pq passin de mi?? vale vale.

  3. Oriol Rius

    doncs ara q m'hi fixo si q tens raó q al teu projecte tb hi és
    això. Com pots veure doncs, encara no me l'he llegit ;)



    Però bueno per si algú vol veure el codi a d'alt engaxat
    però fet pel Carles, aquí va la URL:



    http://oriol.homeip.net/carles/project/report.htm#_Toc8010850



    q també la podries haver posat tu nano ;) i per si algú vol veure
    el projecte del Carles:



    http://oriol.homeip.net/carles/project/report.htm



    apa ja teniu una referència completa. Ah! i a veure si penges el
    projecte en català.



    PD. Has tingut l'honor de ser el primer comentari q he escrit amb el meu
    teclat nou ;) després d 15 anys sense comprar-me un teclat, no ta
    mal,eh?