JavaScript
  Home arrow JavaScript arrow Page 4 - Completing a Network Processor with AJAX
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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? 
JAVASCRIPT

Completing a Network Processor with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-01-03

    Table of Contents:
  • Completing a Network Processor with AJAX
  • Refreshing a previous topic: listing the application's full client-side code
  • Performing real networking tasks on the server: defining the QueryProcessor PHP class
  • Completing the definition for the QueryProcessor class: coding some additional methods
  • Completing the networking application: listing the full source code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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 Network Processor with AJAX - Completing the definition for the QueryProcessor class: coding some additional methods


    (Page 4 of 5 )

    In order to provide the previous "QueryProcessor" class with the capacity for searching DNS records, scanning TCP ports, and so forth, it's necessary obviously to code some additional methods which will perform the aforementioned tasks.

    Having said that, here is the complete signature for this class, this time including the extra methods that I mentioned before. Have a look at it, please:

    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);
      private $validRecTypes=array('A','MX','NS','SOA','PTR',
    'CNAME','AAAA','A6','SRV','NAPTR','ANY');
      public function __construct($host='myhost.com'){
        $this->host=$host;
      }
      // get IP address
      public function getIp(){
        if(!$ip=gethostbyname($this->host)){
          return 'Error resolving host IP address.';
        }
        return $ip;
      }
      // get list of IP addresses
      public function getIpList(){
        if(!$ips=implode(' - ',gethostbynamel($this->host))){
          return 'Error getting list of IP addresses for the provided hostname.';
        }
        return $ips;
      }
      // get host name
      public function getHost(){
        if(!$host=gethostbyaddr($this->getIp())){
          return '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;
      }
      // check for DNS records
      public function checkDNSRecords($recType='MX'){
        if(!in_array($recType,$this->validRecTypes)){
          return 'Invalid DNS record type.';
        }
        if(!checkdnsrr($this->host,$recType)){
          return 'No '.$recType.' records were found.';
        }
        return 'DNS records where found.';
      }           
      // check for DNS records on Windows systems
      public function checkDNSRecordsWin($recType='MX'){
        if(!in_array($recType,$this->validRecTypes)){
          return 'Invalid DNS record type.';
        }
        exec('nslookup -type='.$recType.' '.$this->host,$result);
        foreach($result as $line){
          if(preg_match("/^$this->host/",$line)){
            return 'DNS records were found.';
          }           
        }
        return 'No '.$recType.' records were found.';
      }
      // scan TCP ports
      public function scanPort($port=80){
        if($port<1||$port>65535){
          return 'Invalid TCP port number.';
        }
        $output='Scanning port '.$port.'...please wait.<br />';
        if(!$fp=@fsockopen($this->host,$port,$errno,$errstr,30)){
          return 'Unable to open connection on port '.$port;
        }
        fclose($fp);
        return 'Port '.$port.' is open to connections.';
      }
      // get basic WHOIS info
      public function getWhoIs(){
        $output='Retrieving WHOIS information...please wait.<br />';
        if(!$fp=fsockopen("whois.opensrs.net",43,$errno, $errstr,30)){
          return 'Error opening socket connection to WHOIS server.';
        }
        sleep(2);
        fputs($fp,"$this->hostrn");
        while(!feof($fp)){
          $output.=fread($fp,128).'<br />';
        }
        fclose($fp);
        return $output;
      }
    }

    In this case, the previous class now presents some additional and useful features, like searching for DNS and MX records, scanning TCP ports, and finding basic WHOIS information on a selected Internet host. Indeed, at this point, the query processor class offers a good level of functionality, doesn't it?

    Okay, now that you have seen the complete signature for the prior class, it's time to put all the pieces together, that is the corresponding client and server modules of this networking application, and see how they can work in conjunction. Taking this final step, the application will be completely finished. Don't you feel a bit happier?

    To see the full source code that corresponds to this AJAX-driven networking application, click on the link below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this final article of the series, the AJAX-based networking processor is...
     

    JAVASCRIPT ARTICLES

    - More on JavaScript Array Objects
    - Methods of the DOM Location Object
    - The DOM Location Object Properties
    - Handling Remote Files with JavaScript Click ...
    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





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