Changeset 7768


Ignore:
Timestamp:
Apr 15, 2010, 5:24:10 PM (15 years ago)
Author:
Pieter Naber
Message:

Finished with the Network class, created kml.php for an up-to-date KML file. Waiting for Davids code...

Location:
trunk/src
Files:
4 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/config.php

    r7767 r7768  
    5151 * Values to generate map
    5252 */
    53 $config['kml_file']                     = $config['root']."/map/inc/example.kml";
     53$config['kml_file']                     = $config['root'] . '/map/inc/example.kml';
     54// Should be something like:
     55// $config['kml_file']          = $config['root'] . '/kml.php?time=%TIMESTAMP%';
    5456?>
  • trunk/src/inc/Network.class.php

    r7766 r7768  
    88class Network {
    99        public $netmaskNumber;          // Netmask number
    10         public $netmaskBinair;          // Binair value of netmask address
     10        public $netmaskBinary;          // Binary value of netmask address
    1111        public $netmaskDecimal;         // Decimal value of netmask address
    12         public $wildcardBinair;         // Binair value of wildcard address
     12        public $wildcardBinary;         // Binary value of wildcard address
    1313        public $wildcardDecimal;        // Decimal value of wildcard address
    14         public $networkBinair;          // Binair value of network address
     14        public $networkBinary;          // Binary value of network address
    1515        public $networkDecimal;         // Decimal value of network address
    16         public $broadcastBinair;        // Binair value of broadcast address
     16        public $broadcastBinary;        // Binary value of broadcast address
    1717        public $broadcastDecimal;       // Decimal value of broadcast address
    18         public $hostminBinair;          // Binair value of hostmin address
     18        public $hostminBinary;          // Binary value of hostmin address
    1919        public $hostminDecimal;         // Decimal value of hostmin address
    20         public $hostmaxBinair;          // Binair value of hostmax address
     20        public $hostmaxBinary;          // Binary value of hostmax address
    2121        public $hostmaxDecimal;         // Decimal value of hostmax address
    2222        public $numberHosts;            // Number of possible hosts in this network
     
    2929         */
    3030        public function __construct($ip_address, $ip_netmask) {
    31                 // Binair value of given IP address
    32                 $binair = $this->binIP($ip_address);
     31                // Binary value of given IP address
     32                $binary = $this->binIP($ip_address);
    3333
    3434                // Let's store the IP netmask number
     
    3636
    3737                // Netmask address
    38                 $this->netmaskBinair = str_repeat('1', $ip_netmask) . str_repeat('0', 32 - $ip_netmask);
    39                 $this->netmaskDecimal = $this->decIP($this->netmaskBinair);
     38                $this->netmaskBinary = str_repeat('1', $ip_netmask) . str_repeat('0', 32 - $ip_netmask);
     39                $this->netmaskDecimal = $this->decIP($this->netmaskBinary);
    4040
    4141                // Wildcard address
    42                 $this->wildcardBinair = str_repeat('0', $ip_netmask) . str_repeat('1', 32 - $ip_netmask);
    43                 $this->wildcardDecimal = $this->decIP($this->wildcardBinair);
     42                $this->wildcardBinary = str_repeat('0', $ip_netmask) . str_repeat('1', 32 - $ip_netmask);
     43                $this->wildcardDecimal = $this->decIP($this->wildcardBinary);
    4444
    4545                // Network address
    46                 $this->networkBinair = substr($binair, 0, $ip_netmask) . str_repeat('0', 32 - $ip_netmask);
    47                 $this->networkDecimal = $this->decIP($this->networkBinair);
     46                $this->networkBinary = substr($binary, 0, $ip_netmask) . str_repeat('0', 32 - $ip_netmask);
     47                $this->networkDecimal = $this->decIP($this->networkBinary);
    4848
    4949                // Broadcast address
    50                 $this->broadcastBinair = substr($binair, 0, $ip_netmask) . str_repeat('1', 32 - $ip_netmask);
    51                 $this->broadcastDecimal = $this->decIP($this->broadcastBinair);
     50                $this->broadcastBinary = substr($binary, 0, $ip_netmask) . str_repeat('1', 32 - $ip_netmask);
     51                $this->broadcastDecimal = $this->decIP($this->broadcastBinary);
    5252
    5353                // HostMin address
    54                 $this->hostminBinair = substr($binair, 0, $ip_netmask) . str_repeat('0', 31 - $ip_netmask) . '1';
    55                 $this->hostminDecimal = $this->decIP($this->hostminBinair);
     54                $this->hostminBinary = substr($binary, 0, $ip_netmask) . str_repeat('0', 31 - $ip_netmask) . '1';
     55                $this->hostminDecimal = $this->decIP($this->hostminBinary);
    5656
    5757                // HostMax address
    58                 $this->hostmaxBinair = substr($binair, 0, $ip_netmask) . str_repeat('1', 31 - $ip_netmask) . '0';
    59                 $this->hostmaxDecimal = $this->decIP($this->hostmaxBinair);
     58                $this->hostmaxBinary = substr($binary, 0, $ip_netmask) . str_repeat('1', 31 - $ip_netmask) . '0';
     59                $this->hostmaxDecimal = $this->decIP($this->hostmaxBinary);
    6060
    6161                // Numbers of hosts
    62                 $this->numberHosts = bindec(substr($this->broadcastBinair, $ip_netmask)) - bindec(substr($this->networkBinair, $ip_netmask)) - 1;
     62                $this->numberHosts = bindec(substr($this->broadcastBinary, $ip_netmask)) - bindec(substr($this->networkBinary, $ip_netmask)) - 1;
    6363        }
    6464
     65        /*
     66         * Function: binIP
     67         * Description: Converts a IP address like 192.168.0.1 to it's binary value
     68         * Parameters: string $address
     69         * Returns: string $address_binary
     70         */
    6571        function binIP($address) {
    6672                $address_array = explode('.', $address);
    67                 $address_binair = '';
     73                $address_binary = '';
    6874
    6975                for ($i = 0; $i < 4; $i++) {
    70                         // Create binair value
    71                         $binair = decbin($address_array[$i]);
     76                        // Create binary value
     77                        $binary = decbin($address_array[$i]);
    7278
    7379                        // Trim value to the length
    74                         $binair = trim($binair, 8);
     80                        $binary = trim($binary, 8);
    7581
    7682                        // Add zeros at the left to fit to $size
    77                         $binair = str_repeat('0', 8 - strlen($binair)) . $binair;
     83                        $binary = str_repeat('0', 8 - strlen($binary)) . $binary;
    7884
    79                         $address_binair .= $binair;
     85                        $address_binary .= $binary;
    8086                }
    8187
    82                 return $address_binair;
     88                return $address_binary;
    8389        }
    8490
    85         function decIP($binair) {
     91        /*
     92         * Function: decIP
     93         * Description: Converts a binary IP address to it's decimal value like 192.168.0.1
     94         * Parameters: string $binary
     95         * Returns: string $address
     96         */
     97        function decIP($binary) {
    8698                $address_array = array();
    8799
    88100                for ($i = 0; $i < 4; $i++) {
    89                         $block = substr($binair, $i * 8, 8) . '<br/>';
     101                        $block = substr($binary, $i * 8, 8) . '<br/>';
    90102                        $address_array[] = bindec(intval($block));
    91103                }
    92104
    93                 return implode('.', $address_array);
     105                $address = implode('.', $address_array);
     106
     107                return $address;
    94108        }
    95109
    96         function inNetwork($ip_address) {
    97                 return false;
     110        /*
     111         * Function: compare
     112         * Description: Checks if to networks are the same using network IP address
     113         * Parameters: Network $otherNetwork
     114         * Returns: true if the networks are the same, otherwise false
     115         */
     116        function compare(Network $otherNetwork) {
     117                $check = false;
     118
     119                // Compare the network address
     120                if ($this->networkDecimal == $otherNetwork->networkDecimal) {
     121                        $check = true;
     122                }
     123
     124                return $check;
     125        }
     126
     127        /*
     128         * Function: inNetwork
     129         * Description: Checks if the given IP is in the IP range of the current network
     130         * Parameters: string $ipDecimal
     131         * Returns: true if the IP address is in the IP range, otherwise false
     132         */
     133        function inNetwork($ipDecimal) {
     134                $check = true;
     135
     136                // Check if given IP is bigger than our HostMin IP Address
     137                if (ip2long($ipDecimal) < ip2long($this->hostminDecimal)) {
     138                        $check = false;
     139                }
     140
     141                // Check if given IP is smaller than our HostMax IP Address
     142                if (ip2long($ipDecimal) > ip2long($this->hostmaxDecimal)) {
     143                        $check = false;
     144                }
     145                               
     146                return $check;
    98147        }
    99148}
    100 
    101 $ip = '172.16.0.245';
    102 $network = new Network($ip, 30);
    103 echo    '
    104         Address: ' . $ip . ' / ' . Network::binIP($ip) . '<br/>
    105         Netmask: ' . $network->netmaskDecimal . ' / ' . $network->netmaskBinair . '<br/>
    106         Wildcard: ' . $network->wildcardDecimal . ' / ' . $network->wildcardBinair . '<br/>
    107         Network: ' . $network->networkDecimal . ' / ' . $network->networkBinair . '<br/>
    108         Broadcast: ' . $network->broadcastDecimal . ' / ' . $network->broadcastBinair . '<br/>
    109         HostMin: ' . $network->hostminDecimal . ' / ' . $network->hostminBinair . '<br/>
    110         HostMax: ' . $network->hostmaxDecimal . ' / ' . $network->hostmaxBinair . '<br/>
    111         Hosts/Net: ' . $network->numberHosts . '<br/>';
    112149?>
  • trunk/src/logfile.txt

    r7766 r7768  
    1 Debug (8 | 15:20.40 04/15/10 | ): Reading from file "http://watch.wirelessleiden.nl/nagios/export/node-status.csv"
    2         In file "D:\Workspace\NodeMap2.0\trunk\src\inc\FileHandler.class.php" on line "42"
Note: See TracChangeset for help on using the changeset viewer.