IP Reg is a IPAM tool to keep track of assets, nodes (IP addresses, MAC addresses, DNS aliases) within different subnets, over different locations or even VLAN's. Written in PHP, used with a MySQL-database to have a unique insight in your local network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
ipreg/functions.php

69 lines
1.9 KiB

<?php
// strip mac address to 12 char string
function strip_mac($mac) {
$mac = str_replace('-', '', $mac);
$mac = str_replace(':', '', $mac);
$mac = str_replace('.', '', $mac);
$mac = str_replace(',', '', $mac);
$mac = str_replace(' ', '', $mac);
$mac = strtoupper($mac);
return ($mac);
}
// rebuild mac address
function write_mac($mac) {
// check for invalid mac
if (strlen($mac)!=12) {
return $mac;
} else {
$mac1 = substr($mac, 0, 2);
$mac2 = substr($mac, 2, 2);
$mac3 = substr($mac, 4, 2);
$mac4 = substr($mac, 6, 2);
$mac5 = substr($mac, 8, 2);
$mac6 = substr($mac, 10, 2);
$mac = $mac1 . '-' . $mac2 . '-' . $mac3 . '-' . $mac4 . '-' . $mac5 . '-' . $mac6;
return $mac;
}
}
// redirect page
function header_location($location) {
return header("location: " . $location);
exit;
}
// get location name and that of its parents and return with links to the locations
function location_name($location_id, $seperator) {
// create an array
$location_name = array();
// get location name(s)
$result = mysql_query("SELECT location_name, parent FROM location WHERE location_id='$location_id'");
while ($row = mysql_fetch_object($result)) {
// put this parent before any children
array_unshift($location_name, $row->location_name);
// repeat
location_name($row->parent, '.');
}
// count total no. of found locations
$location_count = count($location_name);
// display location for every array value
for ($i = 0; $i < $location_count; $i++ ) {
echo '<a href="locationview.php?location_id=' . $location_id . '">' . $location_name[$i] . '</a>' . $seperator;
}
}
// calculate page for pagination (pagination is used in subnetview.php)
function page($ip) {
$iprange = explode('.', $ip);
$iprange3 = $iprange[2];
return $iprange3;
}
?>