예제 #1
0
def get_external_ip(verbosity=0):
    v = verbosity
    url = "http://checkip.dyndns.org"
    info(v, "Retreiving current external ip from %s" % url)

    # Open URL
    try:
        html_result = urlopen(url)
    except Exception, e:
        error("Url(%s) - %s" % (url, e))
        return None
예제 #2
0
def update_record(record, ip, verbosity=0):
    v = verbosity
    url = "https://freedns.afraid.org/dynamic/update.php?%s&address=%s"
    url = url % (record.updateKey(), ip)
    info(v, "Updating Record %s" % url)

    # Open URL
    try:
        html_result = urlopen(url)
    except Exception, e:
        error("url(%s) - %s" % (url, e))
        return
예제 #3
0
def get_records(api_key, verbosity=0):
    v = verbosity
    url = "https://freedns.afraid.org/api/?action=getdyndns&sha=%s&style=xml"
    url = url % api_key
    info(v, "Retreiving records from %s" % url)

    # Open URL
    try:
        html_result = urlopen(url)
    except Exception, e:
        error("url(%s) - %s" % (url, e))
        return None
예제 #4
0
    info(v, "Retreiving records from %s" % url)

    # Open URL
    try:
        html_result = urlopen(url)
    except Exception, e:
        error("url(%s) - %s" % (url, e))
        return None

    # Read result
    raw_xml = html_result.read().strip()
    extra(v, "Full XML Result: %s" % raw_xml)

    # Check for authentication error
    if raw_xml == 'ERROR: Could not authenticate.':
        error("Could Not Authenticate")
        return None

    # Parse XML
    try:
        xml = et.fromstring(raw_xml)
    except Exception, e:
        error("XML Parsing Error - %s\nRaw XML: %s" % (e, raw_xml))
        return None

    # Parse xml object into array of dicts
    all_items = xml.findall('item')
    records = [Record(z) for z in [
              {y.tag: y.text for y in x} for x in all_items]]

    extra(v, "Retreived Records: %s" % records)