def test_add_ptr_record(self): from pypdnsrest.dnsrecords import DNSPtrRecord from ipaddress import IPv4Address rec = DNSPtrRecord(self.zone) rec.set_data(IPv4Address(u"192.168.0.1")) z = DNSZone() self.assertTrue(z.add_record(rec))
def parse(self, name: str, data: str, ttl: int) -> DNSRecordBase: if data.lower().find(u"in-addr.arpa".lower()) > 0: data = self._prepare_data(data) from ipaddress import IPv4Address data = IPv4Address(data) elif data.lower().find(u"ip6.arpa".lower()) > 0: data = self._prepare_data(data) data = "".join(data.split(".")) data = ":".join([data[i:i + 4] for i in range(0, len(data), 4)]) from ipaddress import IPv6Address data = IPv6Address(data) else: raise ValueError(u"Invalid PTR value: '{0}'".format(data)) from pypdnsrest.dnsrecords import DNSPtrRecord rec = DNSPtrRecord(name, timedelta(seconds=ttl)) rec.set_data(data) return rec
def test_record_ipv4(self): rec = DNSPtrRecord(self.zone) self.assertTrue(rec.set_data(IPv4Address(u"127.0.0.1")))
def test_get_record(self): rec = DNSPtrRecord(self.zone) rec.set_data(IPv4Address(u"127.0.0.1")) self.assertIsInstance(rec.get_record(), dict)
def test_to_str(self): from ipaddress import IPv4Address rec = DNSPtrRecord(self.zone) rec.set_data(IPv4Address(u"127.0.0.1")) self.assertIsInstance(str(rec), str)
def test_record_empty2(self): rec = DNSPtrRecord(self.zone) with self.assertRaises(InvalidDNSRecordException) as context: rec.set_data(None)
def test_record_ipv6(self): rec = DNSPtrRecord(self.zone) self.assertTrue(rec.set_data(IPv6Address(u"fd12:3456:789a:bcde:f012:3456:789a:bcde")))
# Add A records from ipaddress import IPv4Address from pypdnsrest.dnsrecords import DNSARecord rec = DNSARecord(zone) rec.set_data(IPv4Address("192.168.0.1")) api.add_record(zone, rec) rec = DNSARecord("ns1.{0}".format(zone)) rec.set_data(IPv4Address("192.168.0.1")) api.add_record(zone, rec) rec = DNSARecord("ns2.{0}".format(zone)) rec.set_data(IPv4Address("192.168.0.1")) api.add_record(zone, rec) # Add PTR record from pypdnsrest.dnsrecords import DNSPtrRecord rec = DNSPtrRecord(zone) rec.set_data(IPv4Address("192.168.101.1")) api.add_record(zone, rec) zonedata = api.get_zone(zone) recs = zonedata.get_records() for i in recs: print(i) api.del_zone(zone)