diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..4c81be7cf4efa4aa7da5a9cfbb5b8320f70d27ff --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,12 @@ +image: pandoc/latex + +stages: + - build + +generate pdf: + stage: build + script: + - pandoc -pdf-engine=lualatex --metadata-file=metadata.yml solutions/* -o solutions.pdf + artifacts: + paths: + - solutions.pdf \ No newline at end of file diff --git a/README.md b/README.md index f56cf230e0ce073fdadf2c500719b03274b85f86..4fa4aaa31297e2bf1350e9096e3be6264224e911 100644 --- a/README.md +++ b/README.md @@ -113,3 +113,18 @@ vissza egy üres tuple-lal! - Teszteljük a most megírt modulunkat interaktív módon (indítsunk egy Python interpretert, importáljuk be és hívjuk meg a függvényt) és nézzük meg a modul/függvény dokumentációkat is a `help()` függvénnyel! +## 1.d Feladat - Futtatható DNS szkript + +**Feladat:** Tegyük futtathatóvá az elkészült modult! + + +- [dns_tool2.py.txt](https://qosip.tmit.bme.hu/foswiki/pub/Meres/PythonFeladatok/dns_tool2.py.txt): Skeleton szkript az +1. feladathoz - Nevezzük át a fájlt! + +- A szkriptet ne hagyományos (és mondhatni elavult) shebang sorral definiáljuk, hanem a rugalmasabb és esetünkben fontos +`env` paranccsal (Lásd az 1. Feladat bevezetőjét)! +- Figyeljünk arra, hogy a modul importálható maradjon (ellenőrizzük a `__name__` paramétert)! +- Futtatáshoz ne felejtsünk el futtatási jogot adni a szkriptnek (`$ chmod a+x dns_tool2.py, futtatás: ./dns_tool2.py`)! +- Modul futtatásakor a DNS nevet interaktív módon, a konzolon keresztül kérjük be a megfelelő beépített függvénnyel +(`input()`)! + diff --git a/metadata.yaml b/metadata.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5328b92ccb3044c7ffdb38a91006a723203a0cdb --- /dev/null +++ b/metadata.yaml @@ -0,0 +1,3 @@ +geometry: margin=2cm +lang: hu-HU +output: pdf_document \ No newline at end of file diff --git a/solutions/1_feladat.md b/solutions/1_feladat.md index 3b4e8abd9c916b389a99e4a897b61e6eaed40b68..276807ef5034fd5901de3cbb9fa76ec37dc1c8d5 100644 --- a/solutions/1_feladat.md +++ b/solutions/1_feladat.md @@ -47,6 +47,30 @@ Host alt2.aspmx.l.google.com. has preference 30 **Feladat:** Hosszabb kódok esetén az interaktív interpreter használata körülményes. Írjunk Python modult `dns_tool.py` néven az előző feladatban megvalósított funkcióhoz! +A forráskód: + +```python3 +from dns.resolver import query +from dns.exception import DNSException + + +# input: dns name and optional the type of the record and return all the answered data in a list or in +# case of exception an empty list +def get_mx(dns_name, type="MX"): + try: + answers = query(dns_name, type) + except DNSException: + return [] + ret = [] + for a in answers: + element = (str(a.preference), str(a.exchange)) + ret.append(element) + + return ret +``` + +Futtatás: + ```bash $ python3 >>> import dns_tool @@ -55,8 +79,8 @@ help> dns_tool.get_mx Help on function get_mx in dns_tool: dns_tool.get_mx = get_mx(dns_name, type='MX') - # input: dns name and optional the type of the record and return all the answered data in a list or in case of exception - # an empty list + # input: dns name and optional the type of the record and return all the answered data in a list + # or in case of exception an empty list >>> list = dns_tool.get_mx('google.com') >>> for e in list: ... print(e) @@ -72,4 +96,76 @@ dns_tool.get_mx = get_mx(dns_name, type='MX') ... print(e) ... >>> -``` \ No newline at end of file +``` + +## 1.d Feladat - Futtatható DNS szkript + +**Feladat:** Tegyük futtathatóvá az elkészült modult! + +A forráskód: + +```python3 +#!/usr/bin/env python3 + +from dns.resolver import query +from dns.exception import DNSException + + +# input: dns name and optional the type of the record and return all the answered data in a list or in +# case of exception an empty list +def get_mx(dns_name, type="MX"): + try: + answers = query(dns_name, type) + except DNSException: + return [] + ret = [] + for a in answers: + element = (str(a.preference), str(a.exchange)) + ret.append(element) + + return ret + + +if __name__ == "__main__": + inp = input("Add meg a lekérdezendő domain-t, valamint ha szeretnéd specifikálni, a rekord típusát is szóközzel " + "elválasztva (az alapértelmezett rekord típus az MX): ") + inp = inp.split(" ") + if len(inp) >= 2: + list = get_mx(inp[0], inp[1]) + for e in list: + print(e) + else: + list = get_mx(inp[0]) + for e in list: + print(e) +``` + +Futtatás: + +```bash +$ chmod +x dns_tool2.py +$ ./dns_tool2.py +Add meg a lekérdezendő domain-t, valamint ha szeretnéd specifikálni, a rekord típusát is szóközzel +elválasztva (az alapértelmezett rekord típus az MX): google.com MX ./dns_tool2.py:11: DeprecationWarning: +please use dns.resolver.resolve() instead + answers = query(dns_name, type) +('10', 'aspmx.l.google.com.') +('20', 'alt1.aspmx.l.google.com.') +('50', 'alt4.aspmx.l.google.com.') +('40', 'alt3.aspmx.l.google.com.') +('30', 'alt2.aspmx.l.google.com.') +``` + + +A forráskód: + +```python3 + +``` + +Futtatás: + +```bash + +``` +