def dump(args): """ ref: http://cr.yp.to/djbdns/tinydns-data.html # record type: 'A' : =img0.exampleio.com:211.147.4.31:300; +movie.example.com:211.147.4.31:300 'CNAME' : Cimg1.exampleio.com:img1-exampleio-com.b0.aicdn.com.:86400 'MX' : @example.com::aspmx.l.google.com.:10:ttl 'NS' : .example.com::ns1.example.com.:300; &example.com::ns1.example.com.:300 'TXT' : 'read.example.com:v=spf1 include\072mailgun.org ~all:86400 'GENERIC' : :fqdn:dns_type:rdata:ttl:timestamp:lo (it starts with a colon) 'AAAA' : :ipv6.example.com:28:\052\013\103\100\035\000\000\000\200\000\000\000\000\000\276\357:300 """ dnspod = DNSPod(domain=args.domain) records = dnspod.get_records() records.sort(reverse=True, key=lambda x: x['id']) for record in records: name, type_, value, mx, ttl, enable = record['name'], record['type'], record['value'], \ record['mx'], record['ttl'], int(record['enabled']) domain = args.domain if name == '@' else '.'.join([name, args.domain]) if type_ == 'A': if 'mail' in name: line = DNSPOD_TO_TINYDNS[type_][0].format(domain=domain, value=value, ttl=ttl) else: line = DNSPOD_TO_TINYDNS[type_][1].format(domain=domain, value=value, ttl=ttl) elif type_ == 'AAAA': line = DNSPOD_TO_TINYDNS[type_].format( domain=domain, value=ipv6_addr_to_tinydns_generic(value), ttl=ttl) elif type_ == 'MX': line = DNSPOD_TO_TINYDNS[type_].format(domain=domain, value=value, dist=mx, ttl=ttl) elif type_ == 'TXT': line = DNSPOD_TO_TINYDNS[type_].format(domain=domain, value=value.replace( ':', '\\072'), ttl=ttl) else: line = DNSPOD_TO_TINYDNS[type_].format(domain=domain, value=value, ttl=ttl) if not enable: line = '#' + line output(line)
def list_(args): dnspod = DNSPod(domain=args.domain) params = {} if args.search: params['keyword'] = args.search if args.sub_domain: params['sub_domain'] = args.sub_domain records = dnspod.get_records(**params) output("name", "type", "line", "value", "mx", "ttl", "status") output("-" * 50) for record in records: output(record['name'], record['type'], record['line'], record['value'], (record['mx'] if int(record['mx']) else '-'), record['ttl'], ('enabled' if int(record['enabled']) else 'disabled'))
def list_monitor(args): dnspod = DNSPod(domain=args.domain) monitors = dnspod.get_monitors() monitors = [m for m in monitors if m['domain'] == args.domain] if not args.all: monitors = [m for m in monitors if m['monitor_status'] == 'enabled'] if args.sub_domain: monitors = [m for m in monitors if m['sub_domain'] == args.sub_domain] output('{:>10} {:<12} {:>15} {:>4} {:>5} {:<20} {:<5}'.format( 'sub_domain', 'line', 'ip', 'port', 'type', 'path', 'status')) output('-' * 80) for monitor in monitors: output('{:>10} {:<12} {:>15} {:>4} {:>5} {:<20} {:<5}'.format( monitor['sub_domain'], to_str(monitor['record_line']), monitor['ip'], monitor['port'], monitor['monitor_type'], monitor['monitor_path'], monitor['monitor_status']))
def show(args): dnspod = DNSPod(domain=args.domain) if args.record_line: output('>>>', 'supported lines') for line in dnspod.get_record_lines(): output(line) if args.record_type: output('>>>', 'supported types') for type_ in dnspod.get_record_types(): output(type_) if args.user_log: output('>>>', 'user log') for log_line in dnspod.get_user_log(): output(log_line)