本文整理汇总了PHP中Net_IPv6类的典型用法代码示例。如果您正苦于以下问题:PHP Net_IPv6类的具体用法?PHP Net_IPv6怎么用?PHP Net_IPv6使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Net_IPv6类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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];
}
示例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;
}
}
示例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);
}
示例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
示例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;
}
示例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;
}
示例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
}
}
示例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>';
}
示例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'];
//.........这里部分代码省略.........
示例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']) {
示例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) ";
示例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;
示例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';
示例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]);
}
示例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']);
}