pip install dnspython cryptography aiohttp




Download 0,73 Mb.
Pdf ko'rish
bet9/10
Sana21.05.2024
Hajmi0,73 Mb.
#247422
1   2   3   4   5   6   7   8   9   10
Bog'liq
individual2

pip install dnspython cryptography aiohttp 
2. Shifrlashni boshqarish uchun OpenSSL o'rnatilganligiga ishonch hosil qilish. 
Mana DNSSEC tekshiruvi bilan DNS-resolverni o'rnatadigan va HTTPS 
orqali DNS-ni qo'llab-quvvatlaydigan Python skripti: 
import dns.resolver 
import dns.query 
import dns.message 
import dns.dnssec 
import dns.name 
import dns.rdatatype 
import ssl 


16 
import aiohttp 
import asyncio 
# DNS Resolver Configuration 
DNS_SERVER = '8.8.8.8' # Google's Public DNS for demonstration 
DOH_SERVER = 'https://cloudflare-dns.com/dns-query' 
# Function to resolve DNS with DNSSEC validation 
def resolve_with_dnssec(domain): 
resolver = dns.resolver.Resolver() 
resolver.nameservers = [DNS_SERVER] 
response = resolver.resolve(domain, raise_on_no_answer=False) 
if not response: 
raise Exception("No DNS response received.") 
dnssec_valid = validate_dnssec(domain, response) 
if dnssec_valid: 
print(f"DNSSEC validation successful for {domain}") 
return response 
else: 
raise Exception("DNSSEC validation failed.") 
# Function to validate DNSSEC 


17 
def validate_dnssec(domain, response): 
for rrset in response.response.answer: 
try: 
dns.dnssec.validate(rrset, response.response.answer) 
return True 
except dns.dnssec.ValidationFailure: 
return False 
return False 
# Function to resolve DNS using DNS-over-HTTPS 
async def resolve_with_doh(domain): 
async with aiohttp.ClientSession() as session: 
params = {'name': domain, 'type': 'A'} 
async with session.get(DOH_SERVER, params=params) as resp: 
result = await resp.json() 
if 'Answer' in result: 
print(f"DoH response: {result['Answer']}") 
return result['Answer'] 
else: 
raise Exception("No DoH response received.") 
# Main function to demonstrate both DNSSEC and DoH 
async def main(): 
domain = 'example.com' 


18 
# DNSSEC resolution 
try: 
response = resolve_with_dnssec(domain) 
print(f"DNSSEC response for {domain}: {response}") 
except Exception as e: 
print(f"DNSSEC resolution failed: {e}") 
# DoH resolution 
try: 
doh_response = await resolve_with_doh(domain) 
print(f"DoH response for {domain}: {doh_response}") 
except Exception as e: 
print(f"DoH resolution failed: {e}") 
if __name__ == '__main__': 
asyncio.run(main()) 
1. DNSSEC tekshiruvi: 

Resolution_with_dnssec funksiyasi DNSSEC tekshiruvi bilan DNS ruxsatini 
amalga oshiradi. 

validate_dnssec funksiyasi javobning yaxlitligini ta'minlash uchun DNSSEC 
imzolarini tekshiradi. 
2. HTTPS orqali DNS (DoH): 


19 

Resolution_with_doh funksiyasi HTTPS orqali DoH serveriga (masalan, 
Cloudflare DoH xizmati) DNS so'rovini yuboradi. 

Javob qayta ishlanadi va chop etiladi. 
3. Asosiy funktsiya: 

Berilgan domen (example.com) uchun DNSSEC va DoH rezolyutsiyasidan 
foydalanishni ko'rsatadi. 

Download 0,73 Mb.
1   2   3   4   5   6   7   8   9   10




Download 0,73 Mb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



pip install dnspython cryptography aiohttp

Download 0,73 Mb.
Pdf ko'rish