From c7f14d17c7e810a507339b2ae0889138ca95a175 Mon Sep 17 00:00:00 2001 From: Jason Heiss Date: Mon, 10 Oct 2011 22:14:49 +0000 Subject: [PATCH] Scripts for Apple Airport, FIOS Actiontec MI424WR, and U-verse Residential Gateway (RG) --- airport/AIRPORT-BASESTATION-3-MIB.txt | 461 ++++++++++++++++++++++++++ airport/ddnsreg | 6 + fios/ddnsreg | 64 ++++ uverse/ddnsreg | 97 ++++++ 4 files changed, 628 insertions(+) create mode 100644 airport/AIRPORT-BASESTATION-3-MIB.txt create mode 100644 airport/ddnsreg create mode 100755 fios/ddnsreg create mode 100755 uverse/ddnsreg diff --git a/airport/AIRPORT-BASESTATION-3-MIB.txt b/airport/AIRPORT-BASESTATION-3-MIB.txt new file mode 100644 index 0000000..0854aae --- /dev/null +++ b/airport/AIRPORT-BASESTATION-3-MIB.txt @@ -0,0 +1,461 @@ +AIRPORT-BASESTATION-3-MIB + +DEFINITIONS ::= BEGIN + + IMPORTS + enterprises, MODULE-IDENTITY, OBJECT-TYPE, IpAddress + FROM SNMPv2-SMI + PhysAddress + FROM RFC1213-MIB + DisplayString + FROM SNMPv2-TC; + +baseStation3 MODULE-IDENTITY + LAST-UPDATED "200301160001Z" + ORGANIZATION "Apple Inc." + CONTACT-INFO + " Apple Inc. + Postal: 1 Infinite Loop + Cupertino, CA 95014 + USA + Tel: +1-408-996-1010" + DESCRIPTION + "Management information base in SMI v2 for the AirPort and AirPort Extreme Base Station (v3)." + ::= { airport 3 } + +apple OBJECT IDENTIFIER ::= { enterprises 63 } + +airport OBJECT IDENTIFIER ::= { apple 501 } + +-- (c) 2003-2007 Apple Inc. All rights reserved. Apple, the Apple logo, +-- AirPort, and AirPort Extreme are trademarks of Apple Inc., +-- registered in the U.S. and other countries. +-- +-- IMPORTANT: This Apple software is supplied to you by Apple Inc. +-- ("Apple") in consideration of your agreement to the following +-- terms, and your use, installation, modification or redistribution +-- of this Apple software constitutes acceptance of these terms. If +-- you do not agree with these terms, please do not use, install, +-- modify or redistribute this Apple software. +-- +-- In consideration of your agreement to abide by the following terms, +-- and subject to these terms, Apple grants you a personal, +-- non-exclusive license, under Apple's copyrights in this original +-- Apple software (the "Apple Software"), to use, reproduce, modify +-- and redistribute the Apple Software, with or without modifications, +-- in source and/or binary forms; provided that if you redistribute +-- the Apple Software in its entirety and without modifications, you +-- must retain this notice and the following text and disclaimers in +-- all such redistributions of the Apple Software. Neither the name, +-- trademarks, service marks or logos of Apple Inc. may be used to +-- endorse or promote products derived from the Apple Software without +-- specific prior written permission from Apple. Except as expressly +-- stated in this notice, no other rights or licenses, express or +-- implied, are granted by Apple herein, including but not limited to +-- any patent rights that may be infringed by your derivative works or +-- by other works in which the Apple Software may be incorporated. +-- +-- The Apple Software is provided by Apple on an "AS IS" basis. +-- APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT +-- LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, +-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE +-- APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION +-- WITH YOUR PRODUCTS. +-- +-- IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, +-- INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +-- PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE +-- USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE +-- SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT +-- (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF +-- APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +-- system configuration information + +abs3SysConf OBJECT IDENTIFIER ::= { baseStation3 1 } + +sysConfName OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION "Configured name of the AirPort Base Station." + ::= { abs3SysConf 1 } + +sysConfContact OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION "Configured name of the contact for the AirPort Base Station." + ::= { abs3SysConf 2 } + +sysConfLocation OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION "Configured name of where the AirPort Base Station is located." + ::= { abs3SysConf 3 } + +sysConfUptime OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "Length of time, in seconds, the AirPort Base Station has been running." + ::= { abs3SysConf 4 } + +sysConfFirmwareVersion OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION "Current firmware revision running on the AirPort Base Station." + ::= { abs3SysConf 5 } + +-- TBD: additional configuration/status information +-- NAT state +-- DHCP state +-- briding state +-- product information (Snow, Extreme, etc) +-- USB information +-- list of attached devices, each one with status info +-- print server information +-- list of printers, each one with number of jobs received, +-- logging + + +-- information about wireless clients + +wireless OBJECT IDENTIFIER ::= { baseStation3 2 } + +wirelessNumber OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of wireless clients associated with this AP." + ::= { wireless 1 } + +wirelessClientsTable OBJECT-TYPE + SYNTAX SEQUENCE OF WirelessClient + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "A list of wireless clients." + ::= { wireless 2 } + +wirelessClient OBJECT-TYPE + SYNTAX WirelessClient + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "A wireless client entry containing information about the client." + INDEX { wirelessPhysAddress } + ::= { wirelessClientsTable 1 } + +WirelessClient ::= SEQUENCE { + + -- the following information is provided by the access point driver (i.e., this is information it knows about the wireless STA) + + wirelessPhysAddress + PhysAddress, + wirelessType + INTEGER, + wirelessDataRates + DisplayString, + wirelessTimeAssociated + INTEGER, + wirelessLastRefreshTime + INTEGER, + + -- the following information is obtained from the client, via a communication protocol between the AP and STA/WDS node + -- and therefore, it is only supported by Apple STA/AP drivers + -- the information is refreshed once each time it is requested, but since some STAs will not implement this + -- protocol, we provide an indication of how long it has been since the data was refreshed. if that value + -- is zero, then it means we have never obtained this information from the clients + + wirelessStrength + INTEGER, + wirelessNoise + INTEGER, + wirelessRate + INTEGER, + wirelessNumRX + INTEGER, + wirelessNumTX + INTEGER, + wirelessNumRXErrors + INTEGER, + wirelessNumTXErrors + INTEGER + + } + +wirelessPhysAddress OBJECT-TYPE + SYNTAX PhysAddress + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The MAC address of the wireless client." + ::= { wirelessClient 1 } + +wirelessType OBJECT-TYPE + SYNTAX INTEGER { + sta(1), + wds(2) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The type of wireless client node." + ::= { wirelessClient 2 } + +wirelessDataRates OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The data rates available for the wireless client." + ::= { wirelessClient 3 } + +wirelessTimeAssociated OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The time that this wireless client associated." + ::= { wirelessClient 4 } + +wirelessLastRefreshTime OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of seconds since the client reported its statistics to the AirPort Base Station (-1 if never refreshed or not supported)." + ::= { wirelessClient 5 } + +wirelessStrength OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The signal strength reported by the wireless client (-1 if not supported)." + ::= { wirelessClient 6 } + +wirelessNoise OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The noise reported by the wireless client (-1 if not supported)." + ::= { wirelessClient 7 } + +wirelessRate OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The rate reported by the wireless client (-1 if not supported)." + ::= { wirelessClient 8 } + +wirelessNumRX OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of packets received reported by the wireless client (-1 if not supported)." + ::= { wirelessClient 9 } + +wirelessNumTX OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of packets transmitted reported by this wireless client (-1 if not supported)." + ::= { wirelessClient 10 } + +wirelessNumRXErrors OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of errors encountered receiving packets reported by this wireless client (-1 if not supported)." + ::= { wirelessClient 11 } + +wirelessNumTXErrors OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of errors encountered transmitting packets reported by this wireless client (-1 if not supported)." + ::= { wirelessClient 12 } + +-- information about DHCP server + +dhcpServer OBJECT IDENTIFIER ::= { baseStation3 3 } + +dhcpNumber OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of DHCP clients served by the AirPort base station." + ::= { dhcpServer 1 } + +dhcpClientsTable OBJECT-TYPE + SYNTAX SEQUENCE OF DHCPClient + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "A list of DHCP clients." + ::= { dhcpServer 2 } + +dhcpClient OBJECT-TYPE + SYNTAX DHCPClient + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "A DHCP client entry containing information about the client." + INDEX { dhcpPhysAddress } + ::= { dhcpClientsTable 1 } + +DHCPClient ::= SEQUENCE { + + -- indexed by phys address, since it is unique per client + + dhcpPhysAddress + PhysAddress, + dhcpIpAddress + IpAddress, + dhcpClientID + OCTET STRING, + dhcpLeaseTime + INTEGER + } + +dhcpPhysAddress OBJECT-TYPE + SYNTAX PhysAddress + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The MAC address of the DHCP client." + ::= { dhcpClient 1 } + +dhcpIpAddress OBJECT-TYPE + SYNTAX IpAddress + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The IP address of the DHCP client." + ::= { dhcpClient 2 } + +dhcpClientID OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The DHCP client ID of the DHCP client." + ::= { dhcpClient 3 } + +dhcpLeaseTime OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The lease time for the DHCP client." + ::= { dhcpClient 4 } + + +-- physical interfaces table + +physicalInterfaces OBJECT IDENTIFIER ::= { baseStation3 4 } + +physicalInterfaceCount OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of physical interfaces on the AirPort Base Station. This is different than the number of IP interfaces, as reported by the system MIBs, as the AirPort's bridge typically multiplexes two or more interfaces." + ::= { physicalInterfaces 1 } + +physicalInterfacesTable OBJECT-TYPE + SYNTAX SEQUENCE OF PhysicalInterface + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "List of physical interfaces on the AirPort Base Station." + ::= { physicalInterfaces 2 } + +physicalInterface OBJECT-TYPE + SYNTAX PhysicalInterface + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "Entry containing data about the physical interface on the AirPort Base Station." + INDEX { physicalInterfaceIndex } + ::= { physicalInterfacesTable 1 } + +PhysicalInterface ::= SEQUENCE { + physicalInterfaceIndex INTEGER, + physicalInterfaceName OCTET STRING, + physicalInterfaceUnit INTEGER, + physicalInterfaceSpeed INTEGER, + physicalInterfaceState INTEGER, + physicalInterfaceDuplex INTEGER, + physicalInterfaceNumTX INTEGER, + physicalInterfaceNumRX INTEGER, + physicalInterfaceNumTXError INTEGER, + physicalInterfaceNumRXError INTEGER +} + +physicalInterfaceIndex OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "A unique value for each physical interface. Its value ranges between 1 and the value of physicalInterfaceCount." + ::= { physicalInterface 1 } + +physicalInterfaceName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The name of the physical interface." + ::= { physicalInterface 2 } + +physicalInterfaceUnit OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The unit number of the physical interface." + ::= { physicalInterface 3 } + +physicalInterfaceSpeed OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The speed, in bits per second, of the interface." + ::= { physicalInterface 4 } + +physicalInterfaceState OBJECT-TYPE + SYNTAX INTEGER { + linkDown(0), + linkUp(1) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The status of this interface." + ::= { physicalInterface 5 } + +physicalInterfaceDuplex OBJECT-TYPE + SYNTAX INTEGER { + half(0), + full(1) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The duplex-state of this interface." + ::= { physicalInterface 6 } + +physicalInterfaceNumTX OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of packets transmitted on this interface." + ::= { physicalInterface 7 } + +physicalInterfaceNumRX OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of packets received on this interface." + ::= { physicalInterface 8 } + +physicalInterfaceNumTXError OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of errors during transmission on this interface." + ::= { physicalInterface 9 } + +physicalInterfaceNumRXError OBJECT-TYPE + SYNTAX INTEGER + MAX-ACCESS read-only + STATUS current + DESCRIPTION "The number of errors during reception on this interface." + ::= { physicalInterface 10 } + +END diff --git a/airport/ddnsreg b/airport/ddnsreg new file mode 100644 index 0000000..5671c57 --- /dev/null +++ b/airport/ddnsreg @@ -0,0 +1,6 @@ +#!/bin/sh + +# Unfortunately dhcpClientID is an empty string here, although some +# hosts have a hostname in that field in the GUI utility. +snmpwalk -v 2c -c public -M +. -m AIRPORT-BASESTATION-3-MIB 10.0.1.1 dhcpClientsTable + diff --git a/fios/ddnsreg b/fios/ddnsreg new file mode 100755 index 0000000..f749e6d --- /dev/null +++ b/fios/ddnsreg @@ -0,0 +1,64 @@ +#!/usr/bin/ruby -w + +require 'socket' +require 'openssl' +require 'resolv' + +# In addition to setting these to the appropriate values you'll need to +# enable Advanced -> Local Administration -> Using Secure Telnet over +# SSL Port in the web UI +USERNAME = 'admin' +PASSWORD = 'password' +DDNSKEY = '0f0f0f0f0f0f0f0f0f0f0f==' +DNSDOMAIN = 'example.com' + +def ddns_register(devicename, deviceip) + cleanname = devicename.split('.').first.downcase + ddnsname = "#{cleanname}.#{DNSDOMAIN}" + begin + currentip = Resolv.getaddress(ddnsname) + rescue Resolv::ResolvError + end + if (!currentip || currentip != deviceip) + puts "Need to update #{cleanname}" + IO.popen('nsupdate', 'w') do |pipe| + pipe.puts "key DSL_KEY #{DDNSKEY}" + pipe.puts "update delete #{ddnsname} A" + pipe.puts "update add #{ddnsname} 86400 A #{deviceip}" + pipe.puts "send" + end + end +end + +socket = TCPSocket.new('192.168.1.1', 992) +ssl_context = OpenSSL::SSL::SSLContext.new() +sslsocket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context) +sslsocket.sync_close = true +sslsocket.connect +sslsocket.puts(USERNAME) +sslsocket.puts(PASSWORD) +sslsocket.puts('conf print dev/br0/dhcps/lease') +sslsocket.puts('exit') +parse = false +entry = nil +leases = {} +while line = sslsocket.gets + # Lines end with "\r\r\n", takes a double-chomp to clean them + line.chomp!.chomp! + if line == '(lease' + parse = true + elsif parse + if line =~ /^ \((\d+)/ + entry = $1 + leases[entry] = {} + elsif line =~ /^ \((\w+)\((.*)\)\)/ + key = $1 + value = $2 + leases[entry][key] = value + end + end +end +leases.each_value do |lease| + ddns_register(lease['hostname'], lease['ip']) +end + diff --git a/uverse/ddnsreg b/uverse/ddnsreg new file mode 100755 index 0000000..037813a --- /dev/null +++ b/uverse/ddnsreg @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use LWP::Simple; # get +use Net::hostent; # gethostby* +use Socket; # inet_ntoa + +my $dnsdomain = 'example.com'; +my $ddnskey = '0f0f0f0f0f0f0f0f0f0f0f=='; + +my $devicename; +my $deviceip; +my $address_on_next_line; +my $status_on_next_line; +my $contents = get('http://192.168.1.254/xslt?PAGE=C_2_4') or die; +for (split /^/, $contents) +{ + chomp; + + # Examples: + #

Device: 192.168.1.67

+ #

Device: fog

+ if (/Device: ([^<]+)/) + { + $devicename = $1; + undef $deviceip; + + # Skip devices that didn't provide a name and are thus reported + # by IP address. + if ($devicename =~ /^\d/) + { + undef $devicename; + next; + } + } + elsif (/Current Address/) + { + $address_on_next_line = 1; + } + elsif ($address_on_next_line) + { + $address_on_next_line = 0; + if (/(.+)<\/td>/) + { + $deviceip = $1; + } + } + elsif (/Device Status/) + { + $status_on_next_line = 1; + } + elsif ($status_on_next_line) + { + $status_on_next_line = 0; + if (/Connected DHCP/ && $devicename && $deviceip) + { + ddns_register($devicename, $deviceip); + } + + undef $devicename; + undef $deviceip; + } +} + +sub ddns_register +{ + my ($devicename, $deviceip) = @_; + + my $cleanname = $devicename; + ($cleanname) = split(/\./, $cleanname); + $cleanname = lc($cleanname); + + #print "name: $cleanname, ip: $deviceip\n"; + + my $ddnsname = "$cleanname.$dnsdomain"; + + my $h = gethostbyname($ddnsname); + my $currentip; + if ($h && $h->addr) + { + $currentip = inet_ntoa($h->addr); + } + #print "current ip: $currentip\n"; + + if (!$currentip || $currentip ne $deviceip) + { + print "Need to update $cleanname\n"; + open(my $nsfh, '|-', 'nsupdate') or die; + print $nsfh "key DSL_KEY $ddnskey\n"; + print $nsfh "update delete $ddnsname A\n"; + print $nsfh "update add $ddnsname 86400 A $deviceip\n"; + print $nsfh "send\n"; + close($nsfh); + } +} +