Skip to content
Snippets Groups Projects
Verified Commit d9aadb2f authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

add ci

parent fadebdfa
No related branches found
No related tags found
No related merge requests found
Pipeline #20278 failed
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
...@@ -113,3 +113,18 @@ vissza egy üres tuple-lal! ...@@ -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 - 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! 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()`)!
geometry: margin=2cm
lang: hu-HU
output: pdf_document
\ No newline at end of file
...@@ -47,6 +47,30 @@ Host alt2.aspmx.l.google.com. has preference 30 ...@@ -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` **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! 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 ```bash
$ python3 $ python3
>>> import dns_tool >>> import dns_tool
...@@ -55,8 +79,8 @@ help> dns_tool.get_mx ...@@ -55,8 +79,8 @@ help> dns_tool.get_mx
Help on function get_mx in dns_tool: Help on function get_mx in dns_tool:
dns_tool.get_mx = get_mx(dns_name, type='MX') 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 # input: dns name and optional the type of the record and return all the answered data in a list
# an empty list # or in case of exception an empty list
>>> list = dns_tool.get_mx('google.com') >>> list = dns_tool.get_mx('google.com')
>>> for e in list: >>> for e in list:
... print(e) ... print(e)
...@@ -73,3 +97,75 @@ dns_tool.get_mx = get_mx(dns_name, type='MX') ...@@ -73,3 +97,75 @@ dns_tool.get_mx = get_mx(dns_name, type='MX')
... ...
>>> >>>
``` ```
## 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
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment