Should be functionnal
This commit is contained in:
parent
2c4290a7c6
commit
84b121ace1
|
@ -1,8 +1,11 @@
|
||||||
import requests
|
import requests
|
||||||
import config
|
import config
|
||||||
|
from tldtester.models import TLD
|
||||||
|
from .models import Atlas
|
||||||
|
|
||||||
|
|
||||||
def webrequest():
|
def webrequest(tld, stack):
|
||||||
|
description_string = ("DNS measurement for " + tld + " in IPv" + str(stack))
|
||||||
url = "https://atlas.ripe.net/api/v2/measurements/"
|
url = "https://atlas.ripe.net/api/v2/measurements/"
|
||||||
api_key = config.ATLAS_API
|
api_key = config.ATLAS_API
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -13,9 +16,9 @@ def webrequest():
|
||||||
"definitions": [
|
"definitions": [
|
||||||
{
|
{
|
||||||
"type": "dns",
|
"type": "dns",
|
||||||
"af": 6,
|
"af": stack,
|
||||||
"resolve_on_probe": True,
|
"resolve_on_probe": True,
|
||||||
"description": "DNS measurement for be",
|
"description": description_string,
|
||||||
"query_class": "IN",
|
"query_class": "IN",
|
||||||
"query_type": "SOA",
|
"query_type": "SOA",
|
||||||
"use_macros": False,
|
"use_macros": False,
|
||||||
|
@ -32,7 +35,7 @@ def webrequest():
|
||||||
"timeout": 5000,
|
"timeout": 5000,
|
||||||
"use_probe_resolver": True,
|
"use_probe_resolver": True,
|
||||||
"set_nsid_bit": True,
|
"set_nsid_bit": True,
|
||||||
"query_argument": "be"
|
"query_argument": tld
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"probes": [
|
"probes": [
|
||||||
|
@ -48,12 +51,37 @@ def webrequest():
|
||||||
|
|
||||||
response = requests.post(url, headers=headers, json=data)
|
response = requests.post(url, headers=headers, json=data)
|
||||||
|
|
||||||
print(response.status_code)
|
if response.status_code == 201:
|
||||||
print(response.json())
|
data = (response.json())
|
||||||
print("https://atlas.ripe.net/measurementdetail/")
|
measurement = data['measurements'][0]
|
||||||
|
else:
|
||||||
|
measurement = None
|
||||||
|
dbwriter(tld, stack, measurement)
|
||||||
|
|
||||||
|
def dbwriter(unicodetld, stack, measurement):
|
||||||
|
tld = Atlas.objects.filter(unicodetld=unicodetld)
|
||||||
|
tldstack = tld.filter(stack=stack)
|
||||||
|
if tldstack.exists():
|
||||||
|
primary_key = tldstack.values_list('pk', flat=True).first()
|
||||||
|
db = Atlas.objects.get(pk=primary_key)
|
||||||
|
else:
|
||||||
|
db = Atlas()
|
||||||
|
db.unicodetld = unicodetld
|
||||||
|
db.stack = stack
|
||||||
|
db.measurement = measurement
|
||||||
|
db.save()
|
||||||
|
|
||||||
def dbwriter(response):
|
|
||||||
print(response)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
dbwriter(webrequest())
|
unicodetlds = []
|
||||||
|
# This will get the TLD's in unicode format from the database and put them in the list
|
||||||
|
tlds = TLD.objects.all().order_by('tld')
|
||||||
|
for tld in tlds:
|
||||||
|
db = TLD.objects.get(tld=tld)
|
||||||
|
unicodetlds.append(db.unicodetld)
|
||||||
|
for tld in unicodetlds:
|
||||||
|
webrequest(tld, 4)
|
||||||
|
webrequest(tld, 6)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -5,7 +5,7 @@ class Atlas(models.Model):
|
||||||
STACK = ((0, "Unknown"), (4, "IPv4"), (6, "IPv6"))
|
STACK = ((0, "Unknown"), (4, "IPv4"), (6, "IPv6"))
|
||||||
unicodetld = models.CharField(max_length=100)
|
unicodetld = models.CharField(max_length=100)
|
||||||
stack = models.IntegerField(default=0, choices=STACK)
|
stack = models.IntegerField(default=0, choices=STACK)
|
||||||
measurement = models.IntegerField(default=0)
|
measurement = models.IntegerField(default=0, blank=True, null=True)
|
||||||
lastEdition = models.DateTimeField(auto_now=True)
|
lastEdition = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
Loading…
Reference in a new issue