My favorites | Sign in
Project Logo
                
Changes to /trunk/IPUpdate.py
r0 vs. r2   Edit
  Compare: vs.   Format:
Revision r2
Go to: 
Project members, sign in to write a code review
/trunk/IPUpdate.py /trunk/IPUpdate.py   r2
  1 """
  2 Copyright (c) 2008, Dustin Brewer
  3 All rights reserved.
  4
  5 Redistribution and use in source and binary forms, with or without
  6 modification, are permitted provided that the following conditions are met:
  7
  8 * Redistributions of source code must retain the above copyright notice,
  9 this list of conditions and the following disclaimer.
  10
  11 * Redistributions in binary form must reproduce the above copyright notice,
  12 this list of conditions and the following disclaimer in the documentation
  13 and/or other materials provided with the distribution.
  14
  15 * Neither the name of the The Null Pointer nor the names of its
  16 contributors may be used to endorse or promote products derived from this
  17 software without specific prior written permission.
  18
  19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; u
  25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 """
  30 import urllib, re, sys, os
  31 from pyactiveresource import ActiveResource
  32
  33 # ActiveResource Class for Slicehost DNS API
  34 class Record(ActiveResource):
  35 class Meta:
  36 api_key = '<ENTER API KEY HERE>'
  37 site = ''.join( ['https://', api_key, '@api.slicehost.com/'] );
  38
  39
  40 if len(sys.argv) == 2:
  41 record_id = sys.argv[1]
  42 else:
  43 print ''.join( ['Usage: ', sys.argv[0], ' recordID\n'] )
  44 sys.exit(1)
  45
  46 results = Record.find(id=record_id)
  47 if len(results) != 1:
  48 print "Can't find Record " + record_id + " via SliceHost API."
  49 sys.exit(1)
  50
  51 salon = results[0]
  52 found_ip = (re.findall('[0-9.]+',
  53 urllib.urlopen('http://checkip.dyndns.org/').read())[-1])
  54 if salon.data != found_ip:
  55 salon.data = found_ip
  56 salon.save()
  57 print "IP Updated: " + found_ip
  58 else:
  59 print "IP Unchanged: " + salon.data
  60
  61
Hosted by Google Code