How to use resolve_hostname method in localstack

Best Python code snippet using localstack_python

update_mdns_test.py

Source:update_mdns_test.py Github

copy

Full Screen

1from update_mdns import process_event2import subprocess3import time4def resolve_hostname(hostname):5 result = subprocess.run(["avahi-resolve-host-name", "-4", "-n", hostname], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, input="Hello from the other side")6 if result.returncode != 0 or result.stderr.startswith('Fail'):7 return None8 return result.stdout.rstrip().split()[1]9# Add service with no public ip10process_event({11 "type":"ADDED",12 "object":{13 "metadata":{14 "uid":"cedfd733-0b43-433c-b5dd-844efde8d0f1"15 },16 "status":{"loadBalancer":{}}17 }18})19time.sleep(5)20# Modified service with hostname but no public ip21process_event({22 "type":"MODIFIED",23 "object":{24 "metadata":{25 "uid":"cedfd733-0b43-433c-b5dd-844efde8d0f1",26 "annotations": {27 "mdns.johntrimble.com/hostname": "billybob779.local"28 }29 },30 "status":{"loadBalancer":{}}31 }32})33time.sleep(5)34assert resolve_hostname("billybob779.local") is None35# Modified so we now have an IP address36process_event({37 "type":"MODIFIED",38 "object":{39 "metadata":{40 "uid":"cedfd733-0b43-433c-b5dd-844efde8d0f1",41 "annotations": {42 "mdns.johntrimble.com/hostname": "billybob779.local"43 }44 },45 "status":{"loadBalancer":{"ingress":[{"ip":"192.168.0.199"}]}}46 }47})48time.sleep(5)49assert resolve_hostname("billybob779.local") == "192.168.0.199"50# Change hostname51process_event({52 "type":"MODIFIED",53 "object":{54 "metadata":{55 "uid":"cedfd733-0b43-433c-b5dd-844efde8d0f1",56 "annotations": {57 "mdns.johntrimble.com/hostname": "frank779.local"58 }59 },60 "status":{"loadBalancer":{"ingress":[{"ip":"192.168.0.199"}]}}61 }62})63time.sleep(5)64assert resolve_hostname("billybob779.local") is None65assert resolve_hostname("frank779.local") == "192.168.0.199"66# Change IP address67process_event({68 "type":"MODIFIED",69 "object":{70 "metadata":{71 "uid":"cedfd733-0b43-433c-b5dd-844efde8d0f1",72 "annotations": {73 "mdns.johntrimble.com/hostname": "frank779.local"74 }75 },76 "status":{"loadBalancer":{"ingress":[{"ip":"192.168.0.198"}]}}77 }78})79time.sleep(10)80assert resolve_hostname("frank779.local") == "192.168.0.198"81# Remove service82process_event({83 "type":"DELETED",84 "object":{85 "metadata":{86 "uid":"cedfd733-0b43-433c-b5dd-844efde8d0f1",87 "annotations": {88 "mdns.johntrimble.com/hostname": "frank779.local"89 }90 },91 "status":{"loadBalancer":{"ingress":[{"ip":"192.168.0.198"}]}}92 }93})94time.sleep(5)...

Full Screen

Full Screen

dnsmail.py

Source:dnsmail.py Github

copy

Full Screen

...6"""78import argparse,dns.resolver910def resolve_hostname(hostname, indent=''):11 "Print an A or AAAA record for `hostname`; follow CNAMEs if necessary."12 indent = indent + ' '13 answer = dns.resolver.query(hostname, 'A')14 if answer.rrset is not None:15 for record in answer:16 print(indent, hostname, 'has A address', record.address)17 return18 answer = dns.resolver.query(hostname, 'AAAA')19 20 if answer.rrset is not None:21 for record in answer:22 print(indent, hostname, 'has AAAA address', record.address)23 return24 answer = dns.resolver.query(hostname, 'CNAME')25 if answer.rrset is not None:26 record = answer[0]27 cname = record.address28 print(indent, hostname, 'is a CNAME alias for', cname) #?29 resolve_hostname(cname, indent)30 return31 print(indent, 'ERROR: no A, AAAA, or CNAME records for', hostname)32 33def resolve_email_domain(domain):34 "For an email address `name@domain` find its mail server IP addresses."35 try:36 answer = dns.resolver.query(domain, 'MX', raise_on_no_answer=False)37 except dns.resolver.NXDOMAIN:38 print('Error: No such domain', domain)39 return40 if answer.rrset is not None:41 records = sorted(answer, key=lambda record: record.preference)42 for record in records:43 name = record.exchange.to_text(omit_final_dot=True)44 print('Priority', record.preference)45 resolve_hostname(name)46 else:47 print('This domain has no explicit MX records')48 print('Attempting to resolve it as an A, AAAA, or CNAME')49 resolve_hostname(domain)50 51if __name__ == '__main__':52 parser = argparse.ArgumentParser(description='Find mailserver IP address')53 parser.add_argument('domain', help='domain that you want to send mail to')54 resolve_email_domain(parser.parse_args().domain)55 56 ...

Full Screen

Full Screen

test_net_utils.py

Source:test_net_utils.py Github

copy

Full Screen

2from localstack.constants import LOCALHOST3from localstack.utils.common import short_uid4from localstack.utils.net import resolve_hostname5@pytest.mark.skip_offline6def test_resolve_hostname():7 assert "127." in resolve_hostname(LOCALHOST)8 assert resolve_hostname("example.com")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful