PHP
  Home arrow PHP arrow Page 2 - Completing a Query Processor in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Completing a Query Processor in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2006-05-31


    Table of Contents:
  • Completing a Query Processor in PHP
  • A brief look at the QueryProcessor class
  • Expanding the functionality of the QueryProcessor class: defining the getMXRecords() and checkDNSRecords() methods
  • Scanning TCP ports, running a WHOIS service and more: defining the scanPort() and getWhois() methods
  • Getting the class completed: listing the full source code of the QueryProcessor class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Completing a Query Processor in PHP - A brief look at the QueryProcessor class
    ( Page 2 of 5 )

    Naturally, before I continue adding more methods to the query processor class, it's a good idea to recall how this class was defined. For this reason, below I listed the full source code of the class, as it was written during the previous tutorial:

    class QueryProcessor{
        private $host;
        private $services=array
    ('http','https','ftp','telnet','imap','smtp','nicname',
    'gopher','finger','pop3','www');
        private $ports=array(21,23,25,43,70,79,80,110,143,443);
        public function __construct($host='myhost.com'){
            $this->host=$host;
        }
        // get IP address
        public function getIp(){
            if(!$ip=gethostbyname($this->host)){
                throw new Exception('Error resolving host IP
    address.');
            }
            return $ip;
        }
        // get list of IP addresses
        public function getIpList(){
            if(!$ips=implode(' - ',gethostbynamel($this->host))){
                throw new Exception('Error getting list of IP
    addresses for the provided hostname.');
            }
            return $ips;
        }
        // get host name
        public function getHost(){
            if(!$host=gethostbyaddr($this->getIp())){
                throw new Exception('Error resolving host name.');
            }
            return $host;
        }
        // get TCP ports of Internet services
        public function getServicePorts(){
            $output='Retrieving services ports...Please wait.<br />';
            foreach($this->services as $service){
                if(!$port=getservbyname($service,'tcp')){
                    $output.='Error retrieving port of service
    '.$service.'<br />';
                }
                else{
                    $output.='Service '.$service. ' runs on TCP
    port :'. $port.'<br />';
                }
            }
            return $output;
        }
        // get Services by TCP ports
        public function getServiceNames(){
            $output='Retrieving services names...Please wait.<br />';
            foreach($this->ports as $port){
                if(!$service=getservbyport($port,'tcp')){
                    $output.='Error retrieving service name on port
    '.$port.'<br />';
                }
                else{
                    $output.='TCP Port '.$port. ' is used by
    service :'. $service.'<br />';
                }
            }
            return $output;
        }
        // execute 'ipconfig' command on Windows systems
        public function IpConfig(){
            $output='Running ipconfig command...Please wait.<br />';
            exec('ipconfig',$lines);
            foreach($lines as $line){
                $output.=$line.'<br />';
            }
            return $output;
        }
        // execute 'ping' command on Windows systems
        public function Ping(){
            $output='Running ping command...Please wait.<br />';
            exec('ping '.$this->host,$lines);
            foreach($lines as $line){
                $output.=$line.'<br />';
            }
            return $output;
        }
        // execute 'netstat' command on Windows systems
        public function Netstat(){
            $output='Running netstat command...Please wait.<br />';
            exec('netstat',$lines);
            foreach($lines as $line){
                $output.=$line.'<br />';
            }
            return $output;
        }
        // get MX records on Windows systems
        public function getMXRecordsWin(){
            $output='Retrieving MX Records...please wait.<br />';
            exec("nslookup -type=mx $this->host",$mxhosts);
            foreach($mxhosts as $mxhost){
                $output.=$mxhost.'<br />';
            }
            return $output;
        }
    }

    Okay, that's the complete definition for the "QueryProcessor" class. Now, it's time to move on and continue adding more methods to the class. Go ahead and read the next section. 



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT