2020-04-04 13:02:53 +00:00
|
|
|
---
|
|
|
|
title: Setup
|
|
|
|
---
|
|
|
|
|
2020-06-07 14:44:43 +00:00
|
|
|
<!-- spellchecker-disable -->
|
2020-04-04 13:02:53 +00:00
|
|
|
{{< toc >}}
|
2020-06-07 14:44:43 +00:00
|
|
|
<!-- spellchecker-enable -->
|
2020-04-15 15:00:15 +00:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2020-06-03 15:17:03 +00:00
|
|
|
<!-- prettier-ignore-start -->
|
2020-06-07 14:44:43 +00:00
|
|
|
<!-- spellchecker-disable -->
|
2020-06-03 15:17:03 +00:00
|
|
|
{{< highlight Python "linenos=table" >}}
|
2020-04-15 15:00:15 +00:00
|
|
|
pip install corenetworks
|
2020-06-03 15:17:03 +00:00
|
|
|
{{< /highlight >}}
|
2020-06-07 14:44:43 +00:00
|
|
|
<!-- spellchecker-enable -->
|
2020-06-03 15:17:03 +00:00
|
|
|
<!-- prettier-ignore-end -->
|
2020-04-15 15:00:15 +00:00
|
|
|
|
|
|
|
## Example usage
|
|
|
|
|
2020-06-03 15:17:03 +00:00
|
|
|
<!-- prettier-ignore-start -->
|
|
|
|
<!-- markdownlint-disable -->
|
2020-06-07 14:44:43 +00:00
|
|
|
<!-- spellchecker-disable -->
|
2020-06-03 15:17:03 +00:00
|
|
|
{{< highlight Python "linenos=table" >}}
|
2020-04-15 15:00:15 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from corenetworks import CoreNetworks
|
|
|
|
from corenetworks.exceptions import CoreNetworksException
|
|
|
|
|
|
|
|
try:
|
|
|
|
user = "my_user"
|
|
|
|
password = "my_password"
|
|
|
|
dns = CoreNetworks(user, password, auto_commit=True)
|
|
|
|
|
|
|
|
zones = dns.zones()
|
|
|
|
print(zones)
|
|
|
|
# [{'name': 'example.com', 'type': 'master'}, {'name': 'test.com', 'type': 'master'}]
|
|
|
|
|
|
|
|
zone = dns.zone(zone="example.com")
|
|
|
|
print(zone)
|
|
|
|
# [{'active': True, 'dnssec': True, 'master': None, 'name': 'example.com', 'tsig': None, 'type': 'master'}]
|
|
|
|
|
|
|
|
records = dns.records(zone="example.com")
|
|
|
|
print(records)
|
2020-04-15 15:20:16 +00:00
|
|
|
# [
|
|
|
|
# {'name': '@', 'ttl': '1800', 'type': 'SOA', 'data': 'ns1.core-networks.de. [...]'},
|
|
|
|
# {'name': 'test', 'ttl': '60', 'type': 'A', 'data': '1.2.3.4'},
|
|
|
|
# {'name': '@', 'ttl': '86400', 'type': 'NS', 'data': 'ns1.core-networks.de.'},
|
|
|
|
# {'name': '@', 'ttl': '86400', 'type': 'NS', 'data': 'ns2.core-networks.eu.'},
|
|
|
|
# {'name': '@', 'ttl': '86400', 'type': 'NS', 'data': 'ns3.core-networks.com.'}
|
|
|
|
# ]
|
2020-04-15 15:00:15 +00:00
|
|
|
|
|
|
|
filtered = dns.records(zone="example.com", params={"type": ["A", "AAAA"]})
|
|
|
|
print(filtered)
|
|
|
|
# [{'name': 'test', 'ttl': '3600', 'type': 'A', 'data': '1.2.3.4'}]
|
|
|
|
|
|
|
|
add_record = dns.add_record(
|
|
|
|
zone="example.com", params={
|
|
|
|
"name": "test",
|
|
|
|
"type": "A",
|
|
|
|
"data": "127.0.0.1",
|
|
|
|
"ttl": 3600,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
print(add_record)
|
|
|
|
# [{'name': 'test', 'ttl': '3600', 'type': 'A', 'data': '127.0.0.1'}]
|
|
|
|
|
|
|
|
del_record = dns.delete_record(zone="example.com", params={
|
|
|
|
"name": "test",
|
|
|
|
"type": "A",
|
|
|
|
})
|
|
|
|
print(del_record)
|
|
|
|
# []
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
2020-06-03 15:17:03 +00:00
|
|
|
{{< /highlight >}}
|
2020-06-07 14:44:43 +00:00
|
|
|
<!-- spellchecker-enable -->
|
2020-06-03 15:17:03 +00:00
|
|
|
<!-- markdownlint-restore -->
|
|
|
|
<!-- prettier-ignore-end -->
|