Prev | Current Page 479 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

com", "example.net", or
"example.org" into your web browser.
These domain names are reserved for use in documentation and are not available
for registration. See RFC 2606, Section 3.
410 CHAPTER 16 ?–  NE TWORKING
The second example, shown in Listing 16-1, demonstrates how to use fsockopen()
to build a rudimentary port scanner.
Listing 16-1. Creating a Port Scanner with fsockopen()
// Give the script enough time to complete the task
ini_set("max_execution_time", 120);
// Define scan range
$rangeStart = 0;
$rangeStop = 1024;
// Which server to scan?
$target = "www.example.com";
// Build an array of port values
$range =range($rangeStart, $rangeStop);
echo "

Scan results for $target

";
// Execute the scan
foreach ($range as $port) {
$result = @fsockopen($target, $port,$errno,$errstr,1);
if ($result) echo "

Socket open at port $port

";
}
?>
Scanning www.example.com, the following output is returned:
Scan results for www.example.com:
Socket open at port 21
Socket open at port 25
Socket open at port 80
Socket open at port 110
CHAPTER 16 ?–  NETWORKING 411
A far lazier means for accomplishing the same task involves using a program execution
command such as system() and the wonderful free software package Nmap
(http://insecure.org/nmap/). This method is demonstrated in the section on
common networking tasks.
Mail
This powerful feature of PHP is so darned useful, and needed in so many Web applications,
that this section is likely to be one of the more popular sections of this chapter, if
not the whole book.


Pages:
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491