Home arrow JavaScript arrow Page 3 - Completing a Network Processor with AJAX
JAVASCRIPT

Completing a Network Processor with AJAX


Looking for a comprehensive introduction to creating networking applications with AJAX? Then look no further, because you’ve come to the right place! Welcome to the concluding installment of the series “Creating a Network Processor with AJAX.” As you may have guessed, this series leads you through the development of a highly expansible networking application which uses the capacity of AJAX for sending queries in the background.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
January 03, 2007
TABLE OF CONTENTS:
  1. · Completing a Network Processor with AJAX
  2. · Refreshing a previous topic: listing the application's full client-side code
  3. · Performing real networking tasks on the server: defining the QueryProcessor PHP class
  4. · Completing the definition for the QueryProcessor class: coding some additional methods
  5. · Completing the networking application: listing the full source code

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Completing a Network Processor with AJAX - Performing real networking tasks on the server: defining the QueryProcessor PHP class
(Page 3 of 5 )

As I said in the previous section, the link required for executing real networking commands on the web server will consist simply of a PHP class, which will be capable of performing the variety of tasks that were discussed in the introduction of this article.

Having explained how all the networking operations will be executed on the server, let me show you now the partial definition of this new PHP class , which I called "QueryProcessor." Its signature is as follows:

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;
    }
}

Well, as I explained before, this is the partial definition for the above "QueryProcessor" class. As you can see, the class in question is capable of doing some useful things, like finding the IP address of a given Internet host and listing the name of different services according to their port numbers, running the "ping," "ipconfig" and "netstat" commands on Windows-based systems, retrieving the distinct TCP ports for several services, and so on. Pretty handy, right?

However, as I explained previously, this is only the partial signature for the above class, since it should also be capable of performing some additional tasks, such as searching for DNS records, and scanning specific TCP ports.

Therefore, taking into account this condition, in the next few lines, I'll add some extra methods to the "QueryProcessor," in this way completing its definition.

Wan to see how this will done? Please, keep reading.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials