ndp -an
ping6 -I em0 -c 3 ff02::1
<?php/* Copyright (C) 2014 Deciso B.V. Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com> Copyright (C) 2011 Seth Mos <seth.mos@dds.nl> Copyright (C) 2005 Paul Taylor (paultaylor@winndixie.com) and Manuel Kasper <mk@neon1.net>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/$hostTable = array("host1" => "aa:bb:cc:dd:ee:f0", "host2" => "aa:bb:cc:dd:ee:f1");exec("/usr/sbin/ndp -na", $rawdata);$data = array();array_shift($rawdata);foreach ($rawdata as $line) { $elements = preg_split('/[ ]+/', $line); $ndpent = array(); $ndpent['ipv6'] = trim($elements[0]); $ndpent['mac'] = trim($elements[1]); $ndpent['interface'] = trim($elements[2]); $data[] = $ndpent;}foreach ($hostTable as $key => $value) { $entries = array_keys(array_column($data, 'mac'), $value); foreach ($entries as $entry => $number) { if (substr($data[$number]['ipv6'], -4) === str_replace(':', '', substr($data[$number]['mac'],-5))) { echo $key . " has IPv6 address of " . $data[$number]['ipv6'] . "\n"; /*This is where I would build out the DDNS update. I would start with a query of the DNS server to determine what the IP resolves to and then post an update if needed. You could also cache the last address locally or in a database, etc. */ } }}
netsh interface ipv6 set global randomizeidentifiers=disablednetsh interface ipv6 set privacy state=disabled
<?php/* Copyright (C) 2015 CBA Solutions, LLC Copyright (C) 2014 Deciso B.V. Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com> Copyright (C) 2011 Seth Mos <seth.mos@dds.nl> Copyright (C) 2005 Paul Taylor (paultaylor@winndixie.com) and Manuel Kasper <mk@neon1.net>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/$hostTable = array("example.com" => "aa:bb:cc:dd:ee:f0", "server.example.com" => "aa:bb:cc:dd:ee:f1");$cfEmail = "email@example.com";$cfAPI = "9a7806061c88ada191ed06f989cc3dac";//Code used from OpnSense Sourceexec("/usr/sbin/ndp -na", $rawdata);$data = array();array_shift($rawdata);foreach ($rawdata as $line) { $elements = preg_split('/[ ]+/', $line); $ndpent = array(); $ndpent['ipv6'] = trim($elements[0]); $ndpent['mac'] = trim($elements[1]); $ndpent['interface'] = trim($elements[2]); $data[] = $ndpent;}foreach ($hostTable as $key => $value) { $entries = array_keys(array_column($data, 'mac'), $value); foreach ($entries as $entry => $number) { if (substr($data[$number]['ipv6'], -4) === str_replace(':', '', substr($data[$number]['mac'],-5))) { $domainArray = preg_split("/\./", $key); $cfDomain = $domainArray[count($domainArray)-2] . "." . $domainArray[count($domainArray)-1]; $cfNewIP = $data[$number]['ipv6']; $cfURL = 'https://api.cloudflare.com/client/v4/zones'; //Get the Zone ID $curlRequest = curl_init(); curl_setopt($curlRequest,CURLOPT_HTTPHEADER,array("X-Auth-Email: $cfEmail","X-Auth-Key: $cfAPI","Content-Type: application/json")); $cfURL .= '?' . "name=$cfDomain"; curl_setopt($curlRequest,CURLOPT_URL, $cfURL); curl_setopt($curlRequest,CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curlRequest); curl_close($curlRequest); $cfData = json_decode($result); $cfDomainID = $cfData->result[0]->id; //Get the Zone Record for the FQDN $cfURL = 'https://api.cloudflare.com/client/v4/zones/' . $cfDomainID . '/dns_records?type=AAAA&name=' . $key; $curlRequest = curl_init(); curl_setopt($curlRequest,CURLOPT_HTTPHEADER,array("X-Auth-Email: $cfEmail","X-Auth-Key: $cfAPI","Content-Type: application/json")); curl_setopt($curlRequest,CURLOPT_URL, $cfURL); curl_setopt($curlRequest,CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curlRequest); curl_close($curlRequest); $cfData = json_decode($result); $cfOldIP = $cfData->result[0]->content; $cfHostID = $cfData->result[0]->id; if ($cfOldIP != $cfNewIP){ // Build request to update current IP $curlRequest = curl_init(); $cfUpdate = array(); $cfUpdate["id"] = $cfHostID; $cfUpdate["type"] = "AAAA"; $cfUpdate["name"] = $key; $cfUpdate["content"] = $cfNewIP; $cfUpdate["zone_id"] = $cfDomainID; $cfUpdate["zone_name"] = $cfDomain; $cfUpdate["ttl"] = 300; $cfURL = 'https://api.cloudflare.com/client/v4/zones/' . $cfDomainID . '/dns_records/' . $cfHostID; curl_setopt($curlRequest,CURLOPT_HTTPHEADER,array("X-Auth-Email: $cfEmail","X-Auth-Key: $cfAPI","Content-Type: application/json")); curl_setopt($curlRequest,CURLOPT_RETURNTRANSFER, true); curl_setopt($curlRequest,CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curlRequest,CURLOPT_POSTFIELDS, json_encode($cfUpdate)); curl_setopt($curlRequest,CURLOPT_URL, $cfURL); $result = curl_exec($curlRequest); curl_close($curlRequest); $cfData = json_decode($result); } } }}