• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Net_IPv6类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Net_IPv6的典型用法代码示例。如果您正苦于以下问题:PHP Net_IPv6类的具体用法?PHP Net_IPv6怎么用?PHP Net_IPv6使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Net_IPv6类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_cache

function get_cache($host, $value)
{
    global $dev_cache;
    $host = strtolower(trim($host));
    // Check cache expiration
    $now = time();
    $expired = TRUE;
    if (isset($dev_cache[$host]['lastchecked'])) {
        if ($now - $dev_cache[$host]['lastchecked'] < 3600) {
            $expired = FALSE;
        }
        // will expire after 1 hour
    }
    if ($expired) {
        $dev_cache[$host]['lastchecked'] = $now;
    }
    if (!isset($dev_cache[$host][$value]) || $expired) {
        switch ($value) {
            case 'device_id':
                // Try by hostname
                $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `hostname` = ? OR `sysName` = ?', array($host, $host));
                // If failed, try by IP
                if (!is_numeric($dev_cache[$host]['device_id'])) {
                    $ip = $host;
                    $ip_version = get_ip_version($ip);
                    if ($ip_version !== FALSE) {
                        if ($ip_version == 6) {
                            $ip = Net_IPv6::uncompress($ip, TRUE);
                        }
                        $address_count = dbFetchCell('SELECT COUNT(*) FROM `ipv' . $ip_version . '_addresses` WHERE `ipv' . $ip_version . '_address` = ?;', array($ip));
                        if ($address_count) {
                            $query = 'SELECT `device_id` FROM `ipv' . $ip_version . '_addresses` AS A, `ports` AS I WHERE A.`ipv' . $ip_version . '_address` = ? AND I.`port_id` = A.`port_id`';
                            // If more than one IP address, also check the status of the port.
                            if ($address_count > 1) {
                                $query .= " AND I.`ifOperStatus` = 'up'";
                            }
                            $dev_cache[$host]['device_id'] = dbFetchCell($query, array($ip));
                        }
                    }
                }
                break;
            case 'os':
            case 'version':
                $dev_cache[$host][$value] = dbFetchCell('SELECT `' . $value . '` FROM `devices` WHERE `device_id` = ?', array(get_cache($host, 'device_id')));
                break;
            case 'os_group':
                $os = get_cache($host, 'os');
                $dev_cache[$host]['os_group'] = isset($GLOBALS['config']['os'][$os]['group']) ? $GLOBALS['config']['os'][$os]['group'] : '';
                break;
            default:
                return NULL;
        }
    }
    return $dev_cache[$host][$value];
}
开发者ID:skive,项目名称:observium,代码行数:55,代码来源:syslog.inc.php


示例2: set_host

 /**
  * Set the host. Returns true on success, false on failure (if there are
  * any invalid characters).
  *
  * @access public
  * @param string $host
  * @return bool
  */
 public function set_host($host)
 {
     if ($host === null || $host === '') {
         $this->host = null;
         $this->valid[__FUNCTION__] = true;
         return true;
     } elseif ($host[0] === '[' && substr($host, -1) === ']') {
         if (Net_IPv6::checkIPv6(substr($host, 1, -1))) {
             $this->host = $host;
             $this->valid[__FUNCTION__] = true;
             return true;
         } else {
             $this->host = null;
             $this->valid[__FUNCTION__] = false;
             return false;
         }
     } else {
         $this->host = $this->replace_invalid_with_pct_encoding($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=', SIMPLEPIE_LOWERCASE);
         $this->valid[__FUNCTION__] = true;
         return true;
     }
 }
开发者ID:karlstolley,项目名称:twitter-workshop-cw2010,代码行数:30,代码来源:simplepie.class.php


示例3: ipv62snmp

function ipv62snmp($ipv6)
{
    $ipv6_split = array();
    $ipv6_ex = explode(':', Net_IPv6::uncompress($ipv6));
    for ($i = 0; $i < 8; $i++) {
        $ipv6_ex[$i] = zeropad($ipv6_ex[$i], 4);
    }
    $ipv6_ip = implode('', $ipv6_ex);
    for ($i = 0; $i < 32; $i += 2) {
        $ipv6_split[] = hexdec(substr($ipv6_ip, $i, 2));
    }
    return implode('.', $ipv6_split);
}
开发者ID:syzdek,项目名称:librenms,代码行数:13,代码来源:functions.php


示例4:

  <div id="center">
    <div id="top" style="background: <?php 
echo $config['header_color'];
?>
;">
      <table cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td align="left"></td>
          <td align="right">
  <?php 
if ($_SESSION['authenticated']) {
    echo "Logged in as <b>" . $_SESSION['username'] . "</b> (<a href='?logout=yes'>Logout</a>)";
} else {
    echo "Not logged in!";
}
if (Net_IPv6::checkIPv6($_SERVER['REMOTE_ADDR'])) {
    echo " via <b>IPv6</b>";
} else {
    echo " via <b>IPv4</b>";
}
?>
          </td>
        </tr>
      </table>
    </div>

    <div id="header" style="border: 1px none #ccf;">
      <table width="100%" style="padding: 0px; margin:0px;">
        <tr>
          <td style="padding: 0px; margin:0px; border: none;">
            <div id="logo" style="padding: 10px"><a href="index.php"><img src="<?php 
开发者ID:kyrisu,项目名称:observernms,代码行数:31,代码来源:index.php


示例5: get_status_array


//.........这里部分代码省略.........
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['links']) {
        // warning about deprecated option: $config['warn']['ifdown']
        if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) {
            print_warning("<strong>Config option obsolete</strong>\n                    Please note that config option <strong>\$config['warn']['ifdown']</strong> is now obsolete.\n                    Use options: <strong>\$config['frontpage']['device_status']['ports']</strong> and <strong>\$config['frontpage']['device_status']['errors']</strong>\n                    To remove this message, delete <strong>\$config['warn']['ifdown']</strong> from configuration file.");
        }
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['links'] && !$status['ports']) {
            $query .= 'INNER JOIN `links` as L ON I.`port_id` = L.`local_port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up' ";
        if ($status['links'] && !$status['ports']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'LEFT JOIN `bgpPeers` AS B ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr'];
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:101,代码来源:status.inc.php


示例6: calculateIpCalcResult

/**
 * ipCalc calculations
 */
function calculateIpCalcResult($cidr)
{
    /* first verify address type */
    $type = IdentifyAddress($cidr);
    /* IPv4 */
    if ($type == "IPv4") {
        $net = Net_IPv4::parseAddress($cidr);
        //set ip address type
        $out['Type'] = 'IPv4';
        //calculate network details
        $out['IP address'] = $net->ip;
        // 192.168.0.50
        $out['Network'] = $net->network;
        // 192.168.0.0
        $out['Broadcast'] = $net->broadcast;
        // 192.168.255.255
        $out['Subnet bitmask'] = $net->bitmask;
        // 16
        $out['Subnet netmask'] = $net->netmask;
        // 255.255.0.0
        $out['Subnet wildcard'] = long2ip(~ip2long($net->netmask));
        //0.0.255.255
        //calculate min/max IP address
        $out['Min host IP'] = long2ip(ip2long($out['Network']) + 1);
        $out['Max host IP'] = long2ip(ip2long($out['Broadcast']) - 1);
        $out['Number of hosts'] = ip2long($out['Broadcast']) - ip2long($out['Min host IP']);
        //subnet class
        $out['Subnet Class'] = checkIpv4AddressType($out['Network'], $out['Broadcast']);
        //if IP == subnet clear the Host fields
        if ($out['IP address'] == $out['Network']) {
            $out['IP address'] = "/";
        }
    } else {
        //set ip address type
        $out['Type'] = 'IPv6';
        //calculate network details
        /*         $out['Host address']              = Net_IPv6::removeNetmaskSpec ( $cidr );  */
        $out['Host address'] = $cidr;
        $out['Host address'] = Net_IPv6::compress($out['Host address'], 1);
        $out['Host address (uncompressed)'] = Net_IPv6::uncompress($out['Host address']);
        $mask = Net_IPv6::getNetmaskSpec($cidr);
        $subnet = Net_IPv6::getNetmask($cidr);
        $out['Subnet prefix'] = Net_IPv6::compress($subnet) . '/' . $mask;
        $out['Prefix length'] = Net_IPv6::getNetmaskSpec($cidr);
        // get reverse DNS entries
        $out['Host Reverse DNS'] = calculateReverseDNS6($out['Host address (uncompressed)']);
        $out['Subnet Reverse DNS'] = calculateReverseDNS6($subnet, $mask);
        //if IP == subnet clear the Host fields and Host Reverse DNS
        if ($out['Host address'] == $out['Subnet prefix']) {
            $out['Host address'] = '/';
            $out['Host address (uncompressed)'] = '/';
            unset($out['Host Reverse DNS']);
        }
        //min / max hosts
        $maxIp = gmp_strval(gmp_add(gmp_sub(gmp_pow(2, 128 - $mask), 1), ip2long6($subnet)));
        $out['Min host IP'] = long2ip6(gmp_strval(gmp_add(ip2long6($subnet), 1)));
        $out['Max host IP'] = long2ip6($maxIp);
        $out['Number of hosts'] = MaxHosts($mask, 1);
        //address type
        $out['Address type'] = Net_IPv6::getAddressType($cidr);
        $out['Address type'] = checkIpv6AddressType($out['Address type']);
    }
    /* return results */
    return $out;
}
开发者ID:retexica,项目名称:phpipam,代码行数:68,代码来源:functions-tools.php


示例7: dirname

require dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Sections = new Sections($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# fetch search term
$search_term = $_REQUEST['search_term'];
//initialize Pear IPv6 object
require_once dirname(__FILE__) . '/../../../functions/PEAR/Net/IPv6.php';
$Net_IPv6 = new Net_IPv6();
// ipv6 ?
if ($Net_IPv6->checkIPv6($search_term) != false) {
    $type = "IPv6";
} elseif (strlen($search_term) == 17 && substr_count($search_term, ":") == 5) {
    $type = "mac";
    //count : -> must be 5
} else {
    if (strlen($search_term) == 12 && substr_count($search_term, ":") == 0 && substr_count($search_term, ".") == 0) {
        $type = "mac";
        //no dots or : -> mac without :
    } else {
        $type = $Addresses->identify_address($search_term);
        //identify address type
    }
}
开发者ID:martinsv,项目名称:phpipam,代码行数:31,代码来源:search-results-export.php


示例8: generate_popup_link

/**
 * Generate common popup links which uses ajax/entitypopup.php
 *
 * @param string $type Popup type, see possible types in html/ajax/entitypopup.php
 * @param string $text Text used as link name and ajax data
 * @param array $vars Array for generate url
 * @param string Additional css classes for link
 * @param boolean $escape Escape or not text in url
 * @return string Returns string with link, when hover on this link show popup message based on type
 */
function generate_popup_link($type, $text = NULL, $vars = array(), $class = NULL, $escape = TRUE)
{
    if (!is_string($type) || !is_string($text)) {
        return '';
    }
    if ($type == 'ip') {
        list($ip, $mask) = explode('/', $text, 2);
        $ip_version = get_ip_version($ip);
        if ($ip_version === 6) {
            // Autocompress IPv6 addresses
            $ip = Net_IPv6::compress($ip);
            $text = $ip;
            if (strlen($mask)) {
                $text .= '/' . $mask;
            }
        }
        if (!$ip_version || in_array($ip, array('0.0.0.0', '127.0.0.1', '::', '::1'))) {
            return $text;
        }
    }
    $url = count($vars) ? generate_url($vars) : 'javascript:void(0)';
    // If vars empty, set link not clickable
    $data = $text;
    if ($escape) {
        $text = escape_html($text);
    }
    return '<a href="' . $url . '" class="entity-popup' . ($class ? " {$class}" : '') . '" data-eid="' . $data . '" data-etype="' . $type . '">' . $text . '</a>';
}
开发者ID:Natolumin,项目名称:observium,代码行数:38,代码来源:functions.inc.php


示例9: discover_new_device

function discover_new_device($hostname, $source = 'xdp', $protocol = NULL, $device = NULL, $snmp_port = 161)
{
    global $config;
    $source = strtolower($source);
    // Check if source is enabled for autodiscovery
    if ($config['autodiscovery'][$source]) {
        $flags = OBS_DNS_ALL;
        if (!$protocol) {
            $protocol = strtoupper($source);
        }
        print_cli_data("Try discovering host", "{$hostname} through {$protocol}", 3);
        // By first detect hostname is IP or domain name (IPv4/6 == 4/6, hostname == FALSE)
        $ip_version = get_ip_version($hostname);
        if ($ip_version) {
            // Hostname is IPv4/IPv6
            $use_ip = TRUE;
            $ip = $hostname;
        } else {
            $use_ip = FALSE;
            // Add "mydomain" configuration if this resolves, converts switch1 -> switch1.mydomain.com
            if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'], $flags)) {
                $hostname .= '.' . $config['mydomain'];
            }
            // Determine v4 vs v6
            $ip = gethostbyname6($hostname, $flags);
            if ($ip) {
                $ip_version = get_ip_version($ip);
                print_debug("Host {$hostname} resolved as {$ip}");
            } else {
                // No DNS records
                print_debug("Host {$hostname} not resolved, autodiscovery fails.");
                return FALSE;
            }
        }
        if ($ip_version == 6) {
            $flags = $flags ^ OBS_DNS_A;
            // Exclude IPv4
        }
        if (isset($config['autodiscovery']['ping_skip']) && $config['autodiscovery']['ping_skip']) {
            $flags = $flags | OBS_PING_SKIP;
            // Add skip pings flag
        }
        if (match_network($ip, $config['autodiscovery']['ip_nets'])) {
            print_debug("Host {$hostname} ({$ip}) founded inside configured nets, trying to add:");
            // By first check if pingable
            $pingable = isPingable($ip, $flags);
            if (!$pingable && (isset($config['autodiscovery']['ping_skip']) && $config['autodiscovery']['ping_skip'])) {
                $flags = $flags | OBS_PING_SKIP;
                // Add skip pings flag if allowed in config
                $pingable = TRUE;
            }
            if ($pingable) {
                // Check if device duplicated by IP
                $ip = $ip_version == 4 ? $ip : Net_IPv6::uncompress($ip, TRUE);
                $db = dbFetchRow('SELECT D.`hostname` FROM ipv' . $ip_version . '_addresses AS A
                         LEFT JOIN `ports`   AS P ON A.`port_id`   = P.`port_id`
                         LEFT JOIN `devices` AS D ON D.`device_id` = P.`device_id`
                         WHERE D.`disabled` = 0 AND A.`ipv' . $ip_version . '_address` = ?', array($ip));
                if ($db) {
                    print_debug('Already have device ' . $db['hostname'] . " with IP {$ip}");
                    return FALSE;
                }
                // Detect snmp transport, net-snmp needs udp6 for ipv6
                $snmp_transport = $ip_version == 4 ? 'udp' : 'udp6';
                $new_device = detect_device_snmpauth($ip, $snmp_port, $snmp_transport);
                if ($new_device) {
                    if ($use_ip) {
                        // Detect FQDN hostname
                        // by sysName
                        $snmphost = snmp_get($new_device, 'sysName.0', '-Oqv', 'SNMPv2-MIB');
                        if ($snmphost) {
                            $snmp_ip = gethostbyname6($snmphost, $flags);
                        }
                        if ($snmp_ip == $ip) {
                            $hostname = $snmphost;
                        } else {
                            // by PTR
                            $ptr = gethostbyaddr6($ip);
                            if ($ptr) {
                                $ptr_ip = gethostbyname6($ptr, $flags);
                            }
                            if ($ptr && $ptr_ip == $ip) {
                                $hostname = $ptr;
                            } else {
                                if ($config['autodiscovery']['require_hostname']) {
                                    print_debug("Device IP {$ip} does not seem to have FQDN.");
                                    return FALSE;
                                } else {
                                    $hostname = $ip_version == 4 ? $ip : Net_IPv6::compress($hostname, TRUE);
                                    // Always use compressed IPv6 name
                                }
                            }
                        }
                        print_debug("Device IP {$ip} linked to FQDN name: {$hostname}");
                    }
                    $new_device['hostname'] = $hostname;
                    if (!check_device_duplicated($new_device)) {
                        $snmp_v3 = array();
                        if ($new_device['snmp_version'] === 'v3') {
                            $snmp_v3['snmp_authlevel'] = $new_device['snmp_authlevel'];
//.........这里部分代码省略.........
开发者ID:Natolumin,项目名称:observium,代码行数:101,代码来源:functions.inc.php


示例10: elseif

include "../config.php";
include_once "../includes/definitions.inc.php";
include "includes/functions.inc.php";
include "../includes/functions.inc.php";
include "includes/authenticate.inc.php";
if (!$_SESSION['authenticated']) {
    echo "unauthenticated";
    exit;
}
if ($_GET['query'] && $_GET['cmd']) {
    $host = $_GET['query'];
    $ip = '';
    if (Net_IPv4::validateIP($host)) {
        $ip = $host;
        $ip_version = 4;
    } elseif (Net_IPv6::checkIPv6($host)) {
        $ip = $host;
        $ip_version = 6;
    } else {
        $ip = gethostbyname($host);
        if ($ip && $ip != $host) {
            $ip_version = 4;
        } else {
            $ip = gethostbyname6($host, FALSE);
            if ($ip) {
                $ip_version = 6;
            }
        }
    }
    if ($ip) {
        switch ($_GET['cmd']) {
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:netcmd.php


示例11: array

                echo "Found peer {$peer_ip} (AS{$peer_as})\n";
            }
            $peerlist[] = array('ip' => $peer_ip, 'as' => $peer_as);
        }
    }
    # Foreach
    if ($device['os'] == "junos") {
        ## Juniper BGP4-V2 MIB, ipv6 only for now, because v4 should be covered in BGP4-MIB above
        $peers_cmd = $config['snmpwalk'] . " -M +" . $config['install_dir'] . "/mibs/junos -m BGP4-V2-MIB-JUNIPER -CI -Onq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . ":" . $device['port'] . " ";
        $peers_cmd .= "jnxBgpM2PeerRemoteAs.0.ipv6";
        # FIXME: is .0 the only possible value here?
        $peers = trim(str_replace(".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.", "", `{$peers_cmd}`));
        foreach (explode("\n", $peers) as $peer) {
            list($peer_ip_snmp, $peer_as) = split(" ", $peer);
            # Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
            $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), count(explode('.', $peer_ip_snmp)) - 16))));
            if ($peer) {
                if ($debug) {
                    echo "Found peer {$peer_ip} (AS{$peer_as})\n";
                }
                $peerlist[] = array('ip' => $peer_ip, 'as' => $peer_as);
            }
        }
        # Foreach
    }
    # OS junos
} else {
    echo "No BGP on host";
    if ($device['bgpLocalAs']) {
        mysql_query("UPDATE devices SET bgpLocalAs = NULL WHERE device_id = '" . $device['device_id'] . "'");
        echo " (Removed ASN) ";
开发者ID:kyrisu,项目名称:observernms,代码行数:31,代码来源:bgp-peers.inc.php


示例12: gettext

     if (!is_hostname($_POST['hostname'])) {
         $input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
     } else {
         if (!is_unqualified_hostname($_POST['hostname'])) {
             $input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
         }
     }
 }
 if ($_POST['ipaddrv6']) {
     if (!is_ipaddrv6($_POST['ipaddrv6'])) {
         $input_errors[] = gettext("A valid IPv6 address must be specified.");
     } elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6') {
         $trackifname = $config['interfaces'][$if]['track6-interface'];
         $trackcfg = $config['interfaces'][$trackifname];
         $pdlen = 64 - $trackcfg['dhcp6-ia-pd-len'];
         if (!Net_IPv6::isInNetmask($_POST['ipaddrv6'], '::', $pdlen)) {
             $input_errors[] = sprintf(gettext("The prefix (upper %s bits) must be zero.  Use the form %s"), $pdlen, dhcpv6_pd_str_help($ifcfgsn));
         }
     }
 }
 if (empty($_POST['duid'])) {
     $input_errors[] = gettext("A valid DUID must be specified.");
 }
 /* check for overlaps */
 foreach ($a_maps as $mapent) {
     if (isset($id) && $a_maps[$id] && $a_maps[$id] === $mapent) {
         continue;
     }
     if ($mapent['hostname'] == $_POST['hostname'] && $mapent['hostname'] || $mapent['duid'] == $_POST['duid']) {
         $input_errors[] = gettext("This Hostname, IP or DUID already exists.");
         break;
开发者ID:LFCavalcanti,项目名称:pfsense,代码行数:31,代码来源:services_dhcpv6_edit.php


示例13: foreach

foreach ($cache_arp as $entry) {
    $old_if = $entry['ifIndex'];
    $old_mac = $entry['mac_address'];
    $old_address = $entry['ip_address'];
    $old_version = $entry['ip_version'];
    $old_table[$old_if][$old_version][$old_address] = $old_mac;
}
$ipv4_pattern = '/\\[(\\d+)\\](?:\\[ipv4\\])?\\["?([\\d\\.]+)"?\\]\\s+([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]{1,2})/i';
$ipv6_pattern = '/\\[(\\d+)\\](?:\\[ipv6\\])?\\["?([a-f\\d:]+)"?\\]\\s+(?:([a-f\\d]+):([a-f\\d]+):)?([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]{1,2})/i';
foreach (explode("\n", $oid_data) as $data) {
    if (preg_match($ipv4_pattern, $data, $matches)) {
        $ip = $matches[2];
        $ip_version = 4;
    } elseif (preg_match($ipv6_pattern, $data, $matches)) {
        if (count(explode(':', $matches[2])) === 8) {
            $ip = Net_IPv6::uncompress($matches[2], TRUE);
        } else {
            $ip = hex2ip($matches[2]);
        }
        $ip_version = 6;
    } else {
        // In principle the such shouldn't be.
        continue;
    }
    $if = $matches[1];
    $port_id = $interface[$if];
    if ($ip & $port_id) {
        if ($matches[3] === '' && $matches[4] === '') {
            // Convert IPv4 to fake MAC for 6to4 tunnels
            //ipNetToPhysicalPhysAddress[27][ipv6]["20:02:c0:58:63:01:00:00:00:00:00:00:00:00:00:00"] 0:0:c0:58
            $matches[3] = 'ff';
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:arp-table.inc.php


示例14: foreach

         foreach ($cbgp_oids as $cbgp_oid) {
             $c_oid = $use_cisco_v2 ? str_replace('cbgpPeer', 'cbgpPeer2', $cbgp_oid) : $cbgp_oid;
             echo "{$c_oid} ";
             $c_prefixes = snmpwalk_cache_oid($device, $c_oid, $c_prefixes, 'CISCO-BGP4-MIB', mib_dirs('cisco'));
         }
     }
     #print_vars($bgp_peers);
 }
 $sql = 'SELECT *, `bgpPeers`.bgpPeer_id as bgpPeer_id ';
 $sql .= 'FROM `bgpPeers` ';
 $sql .= 'LEFT JOIN `bgpPeers-state` ON `bgpPeers`.bgpPeer_id = `bgpPeers-state`.bgpPeer_id ';
 $sql .= 'WHERE `device_id` = ?';
 foreach (dbFetchRows($sql, array($device['device_id'])) as $peer) {
     // Poll BGP Peer
     $peer_ip = $peer['bgpPeerRemoteAddr'];
     $remote_ip = strstr($peer_ip, ':') ? Net_IPv6::compress($peer_ip) : $peer_ip;
     // Compact IPv6. Used only for log.
     echo "Checking BGP peer: " . $peer_ip . " ";
     if (!strstr($peer_ip, ':') && !$use_cisco_v2) {
         // Common IPv4 BGP4 MIB
         foreach ($bgp_oids as $bgp_oid) {
             ${$bgp_oid} = $bgp_peers[$peer_ip][$bgp_oid];
         }
     } elseif ($use_cisco_v2) {
         // Cisco BGP4 V2 MIB
         $c_index = strstr($peer_ip, ':') ? 'ipv6.' . ip2hex($peer_ip, ':') : 'ipv4.' . $peer_ip;
         foreach ($bgp_oids as $bgp_oid) {
             $c_oid = str_replace(array('bgpPeer', 'Identifier'), array('cbgpPeer2', 'RemoteIdentifier'), $bgp_oid);
             if ($bgp_oid == 'bgpPeerLocalAddr') {
                 $cisco_peers[$c_index][$c_oid] = hex2ip($cisco_peers[$c_index][$c_oid]);
             }
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:bgp-peers.inc.php


示例15: foreach

}
$sql .= " ORDER BY {$sort}";
if (isset($current)) {
    $limit_low = $current * $rowCount - $rowCount;
    $limit_high = $rowCount;
}
if ($rowCount != -1) {
    $sql .= " LIMIT {$limit_low},{$limit_high}";
}
$sql = "SELECT *,`I`.`ifDescr` AS `interface` {$sql}";
foreach (dbFetchRows($sql, $param) as $interface) {
    $speed = humanspeed($interface['ifSpeed']);
    $type = humanmedia($interface['ifType']);
    if ($_POST['search_type'] == 'ipv6') {
        list($prefix, $length) = explode("/", $interface['ipv6_network']);
        $address = Net_IPv6::compress($interface['ipv6_address']) . '/' . $length;
    } elseif ($_POST['search_type'] == 'mac') {
        $address = formatMac($interface['ifPhysAddress']);
    } else {
        list($prefix, $length) = explode("/", $interface['ipv4_network']);
        $address = $interface['ipv4_address'] . '/' . $length;
    }
    if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) {
        $error_img = generate_port_link($interface, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", errors);
    } else {
        $error_img = "";
    }
    if (port_permitted($interface['port_id'])) {
        $interface = ifLabel($interface, $interface);
        $response[] = array('hostname' => generate_device_link($interface), 'interface' => generate_port_link($interface) . ' ' . $error_img, 'address' => $address, 'description' => $interface['ifAlias']);
    }
开发者ID:job,项目名称:librenms,代码行数:31,代码来源:address-search.inc.php


示例16: rtrim

if (!isset($config['mib_dir'])) {
    $config['mib_dir'] = $config['install_dir'] . '/mibs';
} else {
    $config['mib_dir'] = rtrim($config['mib_dir'], ' /');
}
// Old variable backwards compatibility
if (isset($config['rancid_configs']) && !is_array($config['rancid_configs'])) {
    $config['rancid_configs'] = array($config['rancid_configs']);
}
if (isset($config['auth_ldap_group']) && !is_array($config['auth_ldap_group'])) {
    $config['auth_ldap_group'] = array($config['auth_ldap_group']);
}
// Database currently stores v6 networks non-compressed, check for any compressed subnet and expand them
foreach ($config['ignore_common_subnet'] as $index => $content) {
    if (strstr($content, ':') !== FALSE) {
        $config['ignore_common_subnet'][$index] = Net_IPv6::uncompress($content);
    }
}
// Disable nonexistant features in CE, do not try to turn on, it will not give effect
if (OBSERVIUM_EDITION == 'community') {
    $config['enable_billing'] = 0;
    $config['poller-wrapper']['alerter'] = FALSE;
}
// If we're on SSL, let's properly detect it
// DOCME needs phpdoc block
// TESTME needs unit testing
// MOVEME to includes/common.inc.php
function is_ssl()
{
    if (isset($_SERVER['HTTPS'])) {
        if ('on' == strtolower($_SERVER['HTTPS'])) {
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:definitions.inc.php


示例17: discover_process_ipv6

function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = '')
{
    global $device;
    $ipv6_network = Net_IPv6::getNetmask("{$ipv6_address}/{$ipv6_prefixlen}") . '/' . $ipv6_prefixlen;
    $ipv6_compressed = Net_IPv6::compress($ipv6_address);
    if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) {
        // ignore link-locals (coming from IPV6-MIB)
        return;
    }
    if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
        $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex));
        if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') {
            dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
            echo 'N';
        } else {
            //Update Context
            dbUpdate(array('context_name' => $device['context_name']), 'ipv6_network', '`ipv6_network` = ?', array($ipv6_network));
            echo 'n';
        }
        $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name));
        if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
            dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses');
            echo '+';
        } else {
            //Update Context
            dbUpdate(array('context_name' => $device['context_name']), 'ipv6_address', '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id));
            echo '.';
        }
        $full_address = "{$ipv6_address}/{$ipv6_prefixlen}";
        $valid_address = $full_address . '-' . $port_id;
        $valid['ipv6'][$valid_address] = 1;
    }
    //end if
}
开发者ID:arrmo,项目名称:librenms,代码行数:34,代码来源:functions.inc.php


示例18: list

        list($net, $mask) = explode('/', trim($range));
        if (Net_IPv4::validateIP($net)) {
            // IPv4
            $mask = $mask != NULL ? $mask : '32';
            $range = $net . '/' . $mask;
            if ($mask >= 0 && $mask <= 32 && Net_IPv4::ipInNetwork($_SERVER['REMOTE_ADDR'], $range)) {
                $auth = TRUE;
                // hardcode authenticated for matched subnet
                print_debug("认证的CIDR匹配IPv4 {$range}.");
                break;
            }
        } elseif (Net_IPv6::checkIPv6($net)) {
            // IPv6
            $mask = $mask != NULL ? $mask : '128';
            $range = $net . '/' . $mask;
            if ($mask >= 0 && $mask <= 128 && Net_IPv6::isInNetmask($_SERVER['REMOTE_ADDR'], $range)) {
                $auth = TRUE;
                // hardcode authenticated for matched subnet
                print_debug("认证的CIDR匹配IPv6 {$range}");
                break;
            }
        }
    }
}
if (!$auth) {
    // Normal auth
    include $config['html_dir'] . "/includes/authenticate.inc.php";
}
// Push $_GET into $vars to be compatible with web interface naming
$vars = get_vars('GET');
include $config['html_dir'] . "/includes/graphs/graph.inc.php";
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:graph.php


示例19: gettext

 if ($_POST['network_subnet'] && !is_numeric($_POST['network_subnet'])) {
     $input_errors[] = gettext("A valid destination network bit count must be specified.");
 }
 if ($_POST['gateway'] && is_ipaddr($_POST['network'])) {
     if (!isset($a_gateways[$_POST['gateway']])) {
         $input_errors[] = gettext("A valid gateway must be specified.");
     }
     if (!validate_address_family($_POST['network'], lookup_gateway_ip_by_name($_POST['gateway']))) {
         $input_errors[] = gettext("The gateway '{$a_gateways[$_POST['gateway']]['gateway']}' is a different Address Family as network '{$_POST['network']}'.");
     }
 }
 /* check for overlaps */
 $current_targets = get_staticroutes(true);
 $new_targets = array();
 if (is_ipaddrv6($_POST['network'])) {
     $osn = Net_IPv6::compress(gen_subnetv6($_POST['network'], $_POST['network_subnet'])) . "/" . $_POST['network_subnet'];
     $new_targets[] = $osn;
 }
 if (is_ipaddr($_POST['network'])) {
     if ($_POST['network_subnet'] > 32) {
         $input_errors[] = gettext("A IPv4 subnet can not be over 32 bits.");
     } else {
         $osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
         $new_targets[] = $osn;
     }
 } elseif (is_alias($_POST['network'])) {
     

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Net_LDAP2类代码示例发布时间:2022-05-23
下一篇:
PHP Net_IPv4类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap