/** * 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; }
/** * Transform IP address from decimal to dotted (167903488 -> 10.2.1.0) * * @access public * @param mixed $address * @return void */ public function transform_to_dotted($address) { if ($this->identify_address($address) == "IPv4") { return long2ip($address); } else { return long2ip6($address); } }
if ($action == "ipbans") { stdhead(T_("BANNED_IPS")); navmenu(); if ($do == "del") { if (!@count($_POST["delids"])) { show_error_msg(T_("ERROR"), T_("NONE_SELECTED"), 1); } $delids = array_map('intval', $_POST["delids"]); $delids = implode(', ', $delids); $res = SQL_Query_exec("SELECT * FROM bans WHERE id IN ({$delids})"); while ($row = mysql_fetch_assoc($res)) { SQL_Query_exec("DELETE FROM bans WHERE id={$row['id']}"); # Needs to be tested... if (is_ipv6($row["first"]) && is_ipv6($row["last"])) { $first = long2ip6($row["first"]); $last = long2ip6($row["last"]); } else { $first = long2ip($row["first"]); $last = long2ip($row["last"]); } write_log("IP Ban ({$first} - {$last}) was removed by {$CURUSER['id']} ({$CURUSER['username']})"); } show_error_msg(T_("SUCCESS"), "Ban(s) deleted.", 0); } if ($do == "add") { $first = trim($_POST["first"]); $last = trim($_POST["last"]); $comment = trim($_POST["comment"]); if ($first == "" || $last == "" || $comment == "") { show_error_msg(T_("ERROR"), T_("MISSING_FORM_DATA") . ". Go back and try again", 1); }
/** * Transform IP address from decimal to dotted (167903488 -> 10.2.1.0) */ function Transform2long($ip) { if (IdentifyAddress($ip) == "IPv4") { return long2ip($ip); } else { return long2ip6($ip); } }
} if ($prefix_supported) { switch ($qtype) { case 'SOA': $result = array('result' => array(array('qtype' => 'SOA', 'qname' => $qname, 'content' => implode(" ", $soa), 'ttl' => $soa[6]))); break; default: $ips = $db->table('ipaddresses')->where('dns_name', '=', $qname)->lists('ip_addr'); // Generate $results $results = array(); foreach ($ips as $ip) { // IPv4 if ($ip <= 4294967294) { $results[] = array('qtype' => 'A', 'qname' => $qname, 'content' => long2ip($ip), 'ttl' => $soa[6]); } else { $results[] = array('qtype' => 'AAAA', 'qname' => $qname, 'content' => long2ip6($ip), 'ttl' => $soa[6]); } } if (sizeof($results)) { $result = array('result' => $results); } break; } } } if (!$result) { $result = array('result' => false); } $result['log'] = array("query={$request} response=" . json_encode($result) . " " . date('U')); $response = json_encode($result); echo $response;
/** * Calculates IPv6 from cidr * * @access private * @param mixed $cidr * @return void */ private function calculate_IPv6_calc_results($cidr) { # initialize subnets Class $Subnets = new Subnets($this->Database); # Initialize PEAR NET object $this->initialize_pear_net_IPv6(); # set ip address type $out['Type'] = 'IPv6'; # calculate network details $out['Host address'] = $cidr; $out['Host address'] = $this->Net_IPv6->compress($out['Host address'], 1); $out['Host address (uncompressed)'] = $this->Net_IPv6->uncompress($out['Host address']); $mask = $this->Net_IPv6->getNetmaskSpec($cidr); $subnet = $this->Net_IPv6->getNetmask($cidr); $out['Subnet prefix'] = $this->Net_IPv6->compress($subnet) . '/' . $mask; $out['Prefix length'] = $this->Net_IPv6->getNetmaskSpec($cidr); # get reverse DNS entries $out['Host Reverse DNS'] = $this->reverse_IPv6($out['Host address (uncompressed)']); $out['Subnet Reverse DNS'] = $this->reverse_IPv6($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_pow(2, 128 - $mask), ip2long6($subnet))); $out['Min host IP'] = $subnet; $out['Max host IP'] = long2ip6($maxIp); $out['Number of hosts'] = $Subnets->get_max_hosts($mask, "IPv6"); # set address type $out['Address type'] = $this->get_ipv6_address_type($cidr); # result return $out; }