本文整理汇总了PHP中ip_in_subnet函数的典型用法代码示例。如果您正苦于以下问题:PHP ip_in_subnet函数的具体用法?PHP ip_in_subnet怎么用?PHP ip_in_subnet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ip_in_subnet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find_ip_interface
function find_ip_interface($ip, $bits = null)
{
if (!is_ipaddr($ip)) {
return false;
}
$isv6ip = is_ipaddrv6($ip);
/* if list */
$ifdescrs = get_configured_interface_list();
foreach ($ifdescrs as $ifdescr => $ifname) {
$ifip = $isv6ip ? get_interface_ipv6($ifname) : get_interface_ip($ifname);
if (is_null($ifip)) {
continue;
}
if (is_null($bits)) {
if ($ip == $ifip) {
$int = get_real_interface($ifname);
return $int;
}
} else {
if (ip_in_subnet($ifip, $ip . "/" . $bits)) {
$int = get_real_interface($ifname);
return $int;
}
}
}
return false;
}
示例2: gen_subnet
}
}
if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits'];
$found_if = false;
$found_carp = false;
$found_other_alias = false;
if ($subnet == $if_subnet) {
$found_if = true;
}
$vipiface = $a_vip[$_GET['id']]['interface'];
foreach ($a_vip as $vip_id => $vip) {
if ($vip_id == $_GET['id']) {
continue;
}
if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet)) {
if ($vip['mode'] == "carp") {
$found_carp = true;
} else {
if ($vip['mode'] == "ipalias") {
$found_other_alias = true;
}
}
}
}
if ($found_carp === true && $found_other_alias === false && $found_if === false) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
}
}
if (!$input_errors) {
if (session_status() == PHP_SESSION_NONE) {
示例3: unset
} else {
$pconfig = $_POST;
unset($input_errors);
if (isset($pconfig['enable']) && isset($config['dnsmasq']['enable'])) {
if ($pconfig['port'] == $config['dnsmasq']['port']) {
$input_errors[] = gettext("The DNS Forwarder is enabled using this port. Choose a non-conflicting port, or disable the DNS Forwarder.");
}
}
// forwarding mode requires having valid DNS servers
if (isset($pconfig['forwarding'])) {
$founddns = false;
if (isset($config['system']['dnsallowoverride'])) {
$dns_servers = get_dns_servers();
if (is_array($dns_servers)) {
foreach ($dns_servers as $dns_server) {
if (!ip_in_subnet($dns_server, "127.0.0.0/8")) {
$founddns = true;
}
}
}
}
if (is_array($config['system']['dnsserver'])) {
foreach ($config['system']['dnsserver'] as $dnsserver) {
if (is_ipaddr($dnsserver)) {
$founddns = true;
}
}
}
if ($founddns == false) {
$input_errors[] = gettext("At least one DNS server must be specified under System>General Setup to enable Forwarding mode.");
}
示例4: gettext
if (empty($parent_ip) || empty($parent_sn)) {
$input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface.");
} elseif (!isset($_POST["nonlocalgateway"])) {
$subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn);
$vips = link_interface_to_vips($_POST['interface']);
if (is_array($vips)) {
foreach ($vips as $vip) {
if (!is_ipaddrv6($vip['subnet'])) {
continue;
}
$subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
}
}
$found = false;
foreach ($subnets as $subnet) {
if (ip_in_subnet($_POST['gateway'], $subnet)) {
$found = true;
break;
}
}
if ($found === false) {
$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
}
}
}
}
}
if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) {
if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic")) {
$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration.");
}
示例5: exec
}
}
}
}
}
}
}
$_grb = exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 {$sort_method} {$ratesubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", \$1, \$2, \$4, \$6, \$8 }'", $listedIPs);
$someinfo = false;
for ($x = 2; $x < 12; $x++) {
$bandwidthinfo = $listedIPs[$x];
// echo $bandwidthinfo;
$emptyinfocounter = 1;
if ($bandwidthinfo != "") {
$infoarray = explode(":", $bandwidthinfo);
if ($filter == "all" || $filter == "local" && ip_in_subnet($infoarray[0], $intsubnet) || $filter == "remote" && !ip_in_subnet($infoarray[0], $intsubnet)) {
if ($hostipformat == "") {
// pass back just the raw IP address
$addrdata = $infoarray[0];
} else {
// $hostipformat is one of "hostname", "descr" or "fqdn" - we want a text representation if we can get it.
if ($iplookup[$infoarray[0]] != "") {
// We have a local entry, so use it.
$addrdata = $iplookup[$infoarray[0]];
} else {
// Try to reverse lookup the IP address.
$addrdata = gethostbyaddr($infoarray[0]);
if ($addrdata != $infoarray[0]) {
// Reverse lookup returned something other than the IP address (FQDN, we hope!)
if ($hostipformat != "fqdn") {
// The user does not want the whole FQDN, so only pass back the first part of the name.
示例6: gettext
if (empty($parent_ip) || empty($parent_sn)) {
$input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface.");
} else {
$subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn);
$vips = link_interface_to_vips($pconfig['interface']);
if (is_array($vips)) {
foreach ($vips as $vip) {
if (!is_ipaddrv6($vip['subnet'])) {
continue;
}
$subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
}
}
$found = false;
foreach ($subnets as $subnet) {
if (ip_in_subnet($pconfig['gateway'], $subnet)) {
$found = true;
break;
}
}
if (!$found) {
$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $pconfig['gateway']);
}
}
}
}
if (!empty($config['interfaces'][$pconfig['interface']]['ipaddr'])) {
if (is_ipaddr($config['interfaces'][$pconfig['interface']]['ipaddr']) && (empty($pconfig['gateway']) || $pconfig['gateway'] == "dynamic")) {
$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration.");
}
}
示例7: explode
// Input validation
$reqdfields = explode(" ", "startadr endadr leasecount");
$reqdfieldsn = array(gettext("DHCP range - start"), gettext("DHCP range - end"), gettext("How leases allow"));
$reqdfieldst = explode(" ", "ipaddr ipaddr numeric");
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
do_input_validation_type($_POST, $reqdfields, $reqdfieldsn, $reqdfieldst, $input_errors);
$subnet = $config['interfaces']['lan']['ipaddr'] . "/" . $config['interfaces']['lan']['subnet'];
if (is_ipaddr($_POST['startadr'])) {
if (false == ($cnif = ip_in_subnet($_POST['startadr'], $subnet))) {
$input_errors[] = "Value \"DHCP range - start\" is not belongs to the subnet LAN";
goto out;
} else {
}
}
if (is_ipaddr($_POST['endadr'])) {
if (false == ($cnif = ip_in_subnet($_POST['endadr'], $subnet))) {
$input_errors[] = "Value \"DHCP range - end\" is not belongs to the subnet LAN";
goto out;
} else {
}
}
}
if (empty($input_errors)) {
if (isset($_POST['startadr']) && $_POST['endadr']) {
$config['dnsmasq']['startadr'] = $_POST['startadr'];
$config['dnsmasq']['endadr'] = $_POST['endadr'];
$config['dnsmasq']['leasecount'] = $_POST['leasecount'];
} else {
}
if (isset($_POST['enabletftp'])) {
$config['dnsmasq']['enabletftp'] = TRUE;
示例8: foreach
}
foreach ($staticroutes as $route_subnet) {
list($network, $subnet) = explode("/", $route_subnet);
if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
break;
}
unset($network, $subnet);
}
}
}
if ($_POST['ipaddrv6']) {
if (!is_ipaddrv6($_POST['ipaddrv6'])) {
$input_errors[] = gettext("A valid IPv6 address must be specified.");
} else {
if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
}
$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
if (count($where_ipaddr_configured)) {
$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
foreach ($where_ipaddr_configured as $subnet_conflict) {
$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
}
$input_errors[] = $subnet_conflict_text;
}
foreach ($staticroutes as $route_subnet) {
list($network, $subnet) = explode("/", $route_subnet);
if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
break;
示例9: ip2long
$input_errors[] = "Geçerli bir aralıkta tanımlanmalıdır.";
}
if ($_POST['range_to'] && !is_ipaddr($_POST['range_to'])) {
$input_errors[] = "Geçerli bir aralıkta tanımlanmalıdır.";
}
if ($_POST['gateway'] && !is_ipaddr($_POST['gateway'])) {
$input_errors[] = "Geçerli bir IP gateway IP adresi tanımlanmaldır.";
}
/* make sure the range lies within the bridged subnet */
if ($_POST['bridge']) {
if ($_POST['method'] == "ovpn") {
$ipaddr = $config['interfaces'][$_POST['bridge']]['ipaddr'];
$subnet = $config['interfaces'][$_POST['bridge']]['subnet'];
$subnet_start = ip2long($ipaddr) & gen_subnet_mask_long($subnet);
$subnet_end = ip2long($ipaddr) | ~gen_subnet_mask_long($subnet);
if (!ip_in_subnet($_POST['gateway'], gen_subnet($ipaddr, $subnet) . "/" . $subnet)) {
$input_errors[] = "The specified gateway lies outside of the bridged subnet.";
}
if (ip2long($_POST['range_from']) < $subnet_start || ip2long($_POST['range_from']) > $subnet_end || ip2long($_POST['range_to']) < $subnet_start || ip2long($_POST['range_to']) > $subnet_end) {
$input_errors[] = "The specified range lies outside of the bridged subnet.";
}
if (ip2long($_POST['range_from']) > ip2long($_POST['range_to'])) {
$input_errors[] = "The range is invalid (first element higher than second element).";
}
}
}
/* valid Port */
if (empty($_POST['port'])) {
$input_errors[] = "You must provide a server in between 1 and 65535.";
} else {
if (!is_port($_POST['port'])) {
示例10: foreach
/* make sure no inbound NAT mappings reference this entry */
if (is_array($config['nat']['rule'])) {
foreach ($config['nat']['rule'] as $rule) {
if ($rule['destination']['address'] != "") {
if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
break;
}
}
}
}
if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
$vipiface = $a_vip[$_GET['id']]['interface'];
foreach ($a_vip as $vip) {
if ($vip['interface'] == $vipiface && $vip['mode'] == "carp") {
if (ip_in_subnet($vip['subnet'], gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits'])) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by CARP") . " {$vip['descr']}.";
}
}
}
} else {
if ($a_vip[$_GET['id']]['mode'] == "carp") {
$vipiface = "{$a_vip[$_GET['id']]['interface']}_vip{$a_vip[$_GET['id']]['vhid']}";
foreach ($a_vip as $vip) {
if ($vipiface == $vip['interface'] && $vip['mode'] == "ipalias") {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by ip alias entry") . " {$vip['descr']}.";
}
}
}
}
if (!$input_errors) {
示例11: deleteVIPEntry
/**
* delete virtual ip
*/
function deleteVIPEntry($id)
{
global $config;
$input_errors = array();
$a_vip =& $config['virtualip']['vip'];
/* make sure no inbound NAT mappings reference this entry */
if (isset($config['nat']['rule'])) {
foreach ($config['nat']['rule'] as $rule) {
if (!empty($rule['destination']['address'])) {
if ($rule['destination']['address'] == $a_vip[$id]['subnet']) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
break;
}
}
}
}
if (is_ipaddrv6($a_vip[$id]['subnet'])) {
$is_ipv6 = true;
$subnet = gen_subnetv6($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']);
$if_subnet_bits = get_interface_subnetv6($a_vip[$id]['interface']);
$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$id]['interface']), $if_subnet_bits);
} else {
$is_ipv6 = false;
$subnet = gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']);
$if_subnet_bits = get_interface_subnet($a_vip[$id]['interface']);
$if_subnet = gen_subnet(get_interface_ip($a_vip[$id]['interface']), $if_subnet_bits);
}
$subnet .= "/" . $a_vip[$id]['subnet_bits'];
$if_subnet .= "/" . $if_subnet_bits;
if (isset($config['gateways']['gateway_item'])) {
foreach ($config['gateways']['gateway_item'] as $gateway) {
if ($a_vip[$id]['interface'] != $gateway['interface']) {
continue;
}
if ($is_ipv6 && $gateway['ipprotocol'] == 'inet') {
continue;
}
if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6') {
continue;
}
if (ip_in_subnet($gateway['gateway'], $if_subnet)) {
continue;
}
if (ip_in_subnet($gateway['gateway'], $subnet)) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
break;
}
}
}
if ($a_vip[$id]['mode'] == "ipalias") {
$subnet = gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']) . "/" . $a_vip[$id]['subnet_bits'];
$found_if = false;
$found_carp = false;
$found_other_alias = false;
if ($subnet == $if_subnet) {
$found_if = true;
}
$vipiface = $a_vip[$id]['interface'];
foreach ($a_vip as $vip_id => $vip) {
if ($vip_id != $id) {
if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet)) {
if ($vip['mode'] == "carp") {
$found_carp = true;
} else {
if ($vip['mode'] == "ipalias") {
$found_other_alias = true;
}
}
}
}
}
if ($found_carp === true && $found_other_alias === false && $found_if === false) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
}
}
if (count($input_errors) == 0) {
// Special case since every proxyarp vip is handled by the same daemon.
if ($a_vip[$id]['mode'] == "proxyarp") {
$viface = $a_vip[$id]['interface'];
unset($a_vip[$id]);
interface_proxyarp_configure($viface);
} else {
interface_vip_bring_down($a_vip[$id]);
unset($a_vip[$id]);
}
if (count($config['virtualip']['vip']) == 0) {
unset($config['virtualip']['vip']);
}
}
return $input_errors;
}
示例12: array_search_ex
if ($_POST['mode'] == "new") {
if (is_macaddr($_POST['macaddr'])) {
if (is_array($a_hosts)) {
$index = array_search_ex($_POST['macaddr'], $a_hosts, "macaddr");
if (FALSE !== ($index = array_search_ex($_POST['macaddr'], $a_hosts, "macaddr"))) {
$input_errors[] = "MAC adress exist. It must be unique";
goto out;
} else {
}
} else {
}
}
}
$subnet = $config['interfaces']['lan']['ipaddr'] . "/" . $config['interfaces']['lan']['subnet'];
if (is_ipaddr($_POST['ipadress'])) {
if (false == ($cnif = ip_in_subnet($_POST['ipadress'], $subnet))) {
$input_errors[] = "Value \"IP address\" is not belongs to the subnet LAN";
goto out;
} else {
}
}
} elseif (empty($_POST['macaddr']) && empty($_POST['ipadress']) && !empty($_POST['hostname'])) {
if (FALSE == is_hostname($_POST['hostname'])) {
$input_errors[] = "Wrong Host name.";
goto out;
} else {
$pconfig['leasetime'] = "60";
$nas4frehosts =& $config['system']['hosts'];
if (false !== ($cnin = array_search_ex($_POST['hostname'], $nas4frehosts, "name"))) {
$warning_mess = "Host defined on <a href=system_hosts.php>/etc/hosts</a>";
} else {
示例13: explode
}
$reqdfields = explode(" ", "server");
$reqdfieldsn = explode(",", "Hedef Sunucu");
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
if ($_POST['server'] && !is_ipaddr($_POST['server'])) {
$input_errors[] = "Geçerli bir hedef IP adresi tanımlanmalıdır.";
}
if (!$input_errors) {
/* make sure that the DHCP server isn't enabled on this interface */
if (isset($config['dhcpd'][$if]['enable'])) {
$input_errors[] = "You must disable the DHCP server on the {$iflist[$if]} interface before enabling the DHCP Relay.";
}
/* make sure that the DHCP server isn't running on any of the implied interfaces */
foreach ($config['interfaces'] as $ifname => $ifcfg) {
$subnet = $ifcfg['ipaddr'] . "/" . $ifcfg['subnet'];
if (ip_in_subnet($_POST['server'], $subnet)) {
$destif = $ifname;
}
}
if (!isset($destif)) {
$destif = "wan";
}
if (isset($config['dhcpd'][$destif]['enable'])) {
$input_errors[] = "You must disable the DHCP server on the {$destif} interface before enabling the DHCP Relay.";
}
/* if proxydhcp is selected, make sure DHCP is enabled on WAN */
if (isset($config['dhcrelay']['proxydhcp']) && $config['interfaces']['wan']['ipaddr'] != "dhcp") {
$input_errors[] = "You must have DHCP active on the WAN interface before enabling the DHCP proxy option.";
}
}
}
示例14: return_first_two_octets
}
}
if ($_POST['password'] == "") {
$input_errors[] = "VHID üyeleri arasında bir şifre paylaşımı tanımı yapılmalıdır.";
}
$can_post = true;
$found = false;
$subnet_ip = return_first_two_octets($_POST['subnet']);
$iflist = array("lan", "wan");
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
$iflist['opt' . $i] = 'opt' . $i;
}
foreach ($iflist as $if) {
$ww_subnet_ip = $config['interfaces'][$if]['ipaddr'];
$ww_subnet_bits = $config['interfaces'][$if]['subnet'];
if (ip_in_subnet($_POST['subnet'], gen_subnet($ww_subnet_ip, $ww_subnet_bits) . "/" . $ww_subnet_bits)) {
$found = true;
}
}
if ($found == false) {
$cannot_find = $_POST['subnet'] . "/" . $_POST['subnet_bits'];
$can_post = false;
}
if ($can_post == false) {
$input_errors[] = " (\$ cannot_find) için eşleşen bir alt ağ ile arayüz bulunamadı. Lütfen bu alt için gerçek bir arabirime bir IP ekleyin.";
}
}
if (!$input_errors) {
$vipent = array();
$vipent['mode'] = $_POST['mode'];
$vipent['interface'] = $_POST['interface'];
示例15: get_interface_ip
}
break;
case 'ipalias':
if (strstr($_POST['interface'], "_vip")) {
if (is_ipaddrv4($_POST['subnet'])) {
$parent_ip = get_interface_ip($_POST['interface']);
$parent_sn = get_interface_subnet($_POST['interface']);
$subnet = gen_subnet($parent_ip, $parent_sn);
} else {
if (is_ipaddrv6($_POST['subnet'])) {
$parent_ip = get_interface_ipv6($_POST['interface']);
$parent_sn = get_interface_subnetv6($_POST['interface']);
$subnet = gen_subnetv6($parent_ip, $parent_sn);
}
}
if (isset($parent_ip) && !ip_in_subnet($_POST['subnet'], "{$subnet}/{$parent_sn}") && !ip_in_interface_alias_subnet(link_carp_interface_to_parent($_POST['interface']), $_POST['subnet'])) {
$cannot_find = $_POST['subnet'] . "/" . $_POST['subnet_bits'];
$input_errors[] = sprintf(gettext("Sorry, we could not locate an interface with a matching subnet for %s. Please add an IP alias in this subnet on this interface."), $cannot_find);
}
unset($parent_ip, $parent_sn, $subnet);
}
break;
default:
if ($_POST['interface'] == 'lo0') {
$input_errors[] = gettext("For this type of vip localhost is not allowed.");
} else {
if (strpos($_POST['interface'], '_vip')) {
$input_errors[] = gettext("A CARP parent interface can only be used with IP Alias type Virtual IPs.");
}
}
break;