PHP Classes

File: adv_net.php

Recommend this page to a friend!
  Classes of Tomasz Malewski   adv_net   adv_net.php   Download  
File: adv_net.php
Role: Class source
Content type: text/plain
Description: Main class
Class: adv_net
Analyze the local network with nmap
Author: By
Last change: plain text
When set as html - missing lines
Date: 16 years ago
Size: 3,300 bytes
 

Contents

Class file image Download
<?

// PHP class for NMAP under linux by Tomasz Malewski , Warsaw/Poland , Built 20081123
// depend function it requires access to NMAP , arping , host .
// If class works strange i suggest this record in /etc/sudoers
// ALL ALL=NOPASSWD: /usr/bin/nmap
// ALL ALL=NOPASSWD: /usr/sbin/arping
class adv_net
{
// var $ip,$status,$extra,$debug;

   
function ping() // Ping function return status
   
{
   
exec("sudo nmap ".$this->ip." -sP -n ".$this->cmd_extra." | grep 'host up'",$shell_out);
    if (
$this->cmd_debug==1) print_r ($shell_out); // DEBUG
   
if (strlen($shell_out[0])!='0')
        {
$this -> hosts[$this->ip][up]="1";}
        else
        {
$this -> hosts[$this->ip][up]="0";}
      }
// function ping


   
function ip2mac() // IP to MAC converter
   
{
   
exec("sudo arping ".$this->ip." -c1 ".$this->cmd_extra." | grep '\[*\]'",$shell_out);
    if (
$this->cmd_debug==1) print_r ($shell_out); // DEBUG
   
preg_match ("/\ \[(.*?)\] /",$shell_out[0],$mac);
   
$this->hosts[$this->ip][mac]=$mac[1];
    }
// ip2mac

   
function rdns() // rDNS lookup
   
{
   
exec("host ".$this->ip." ".$this->cmd_extra." | grep Name",$shell_out);
    if (
$this->cmd_debug==1) print_r ($shell_out); // DEBUG
   
preg_match ("/Name: (.*)/",$shell_out[0],$rdns);
   
$this->hosts[$this->ip][name]=$rdns[1];
    }
// function rDNS

   
function dns() // DNS lookup
   
{
   
exec("host ".$this->ip_hostname." ".$this->cmd_extra." | grep ".$this->ip_hostname,$shell_out);
    if (
$this->cmd_debug==1) print_r ($shell_out); // DEBUG
   
preg_match ("/".$this->ip_hostname."(\s*)([^\s.]*)(\s*)(.*)/",$shell_out[0],$dns);
    if (
$this->cmd_debug==1) print_r ($dns); // DEBUG
   
$this->hosts[$dns[4]][name]=$this->ip_hostname;
    }
// function DNS

   
function lan_discovery($subnet) // Require subnet ex 24 for C subnet, or 32 for one IP.
   
{
   
exec("nmap -sL ".$this->ip."/$subnet ".$this->cmd_extra,$shell_out);
    if (
$this->cmd_debug==1) print_r ($shell_out); // DEBUG
   
$counter='0';
    foreach (
$shell_out as $line)
                {
       
$hostup=preg_match ('/Host (.*?) \((.*?)\)/',$line,$line2);
        if (
$this->cmd_debug==1) print_r ( $line2); // DEBUG
       
if ($hostup==1)
            {
// $this->host_up[$counter][0]=trim($line2[2]); // old concept
// $this->host_up[$counter][1]=trim($line2[1]); // old conecpt
           
$this->hosts[trim($line2[2])][name]=trim($line2[1]);
           
$counter++;
            }
// if hostup==1
       
} // foreach shell_out
   
} // lan_discovery

function port_discovery()
    {
   
exec("nmap ".$this->ip." -sV ".$this->cmd_extra." | grep [0-9]/",$shell_out);
    if (
$this->cmd_debug==1) print_r ($shell_out); // DEBUG
   
foreach ($shell_out as $line)
                {
       
$port=preg_match ('/([0-9]*)\/([a-z]*)(\s*)([a-z]*)(\s*)(.*) /',$line,$line2);
        if (
$this->cmd_debug==1) print_r ( $line2); // DEBUG
       
if ($port==1)
            {
           
$this->hosts[$this->ip][ports][trim($line2[1])]=trim($line2[6]);
// $port_list[$counter][1]=trim($line2[1]); // old concept
// $port_list[$counter][2]=trim($line2[2]);
// $port_list[$counter][3]=trim($line2[3]);
// $port_list[$counter][4]=trim($line2[4]);
           
$counter++;
            }
// if port==1
       
} // foreach shell_out
   
} // scan_ports


} // class adv_net