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

46 lines
1.3 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) {
if (strlen($mac)!=12) {
// if the MAC is empty, or for whatever reason incorrect, just return
return $mac;
} else {
// length is good, continue
$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);
// check session for preference (if 0, do nothing), if changed: update useredit.php too!
if ($_SESSION['suser_mac']==1) {
$mac = $mac1 . '-' . $mac2 . '-' . $mac3 . '-' . $mac4 . '-' . $mac5 . '-' . $mac6;
} else if ($_SESSION['suser_mac']==2) {
$mac = $mac1 . ':' . $mac2 . ':' . $mac3 . ':' . $mac4 . ':' . $mac5 . ':' . $mac6;
} else if ($_SESSION['suser_mac']==3) {
$mac = $mac1 . $mac2 . $mac3 . '-' . $mac4 . $mac5 . $mac6;
}
return $mac;
}
}
// redirect page
function header_location($location) {
header("location: " . $location);
exit;
}
?>