Best Python code snippet using tempest_python
module_checker.py
Source:module_checker.py
...82 """83 self.url_list = url_list84 self.sem = asyncio.Semaphore(512)85 self.loop = asyncio.get_event_loop()86 self.dns_servers = get_dns_servers(dns_server_count)87 self.resolver = aiodns.DNSResolver(loop=self.loop, servers=self.dns_servers, timeout=2, tries=2, rotate=True)88 self.cname_results = {}89 async def fetch(self, url):90 async with self.sem:91 try:92 response = await self.resolver.query(url,'CNAME')93 self.cname_results.update({url:response.cname})94 return { "url": url, "cname": response.cname } if response.cname is not None else None95 except Exception as e:96 print("Error: {}".format(e))97 return None98 async def tasker(self):99 tasks = []100 for url in self.url_list:101 task = asyncio.ensure_future(self.fetch(url))102 tasks.append(task)103 responses = asyncio.gather(*tasks, return_exceptions=True, loop=self.loop)104 await responses105 106 def run(self):107 print("DNS servers: {}".format(self.dns_servers))108 future = asyncio.ensure_future(self.tasker())109 self.loop.run_until_complete(future)110 return self.cname_results111def get_dns_servers(count):112 try:113 r = requests.get('https://public-dns.info/nameserver/us.json')114 data = json.loads(r.text)115 servers = [i['ip'] for i in data if (i['reliability'] == 1)]116 servers_prune = servers[:count]117 return(servers_prune)118 except Exception as e:119 print("get_dns_servers error: {}".format(e))...
win_dns_client.py
Source:win_dns_client.py
...18 '''19 if salt.utils.is_windows():20 return 'win_dns_client'21 return (False, "Module win_dns_client: module only works on Windows systems")22def get_dns_servers(interface='Local Area Connection'):23 '''24 Return a list of the configured DNS servers of the specified interface25 CLI Example:26 .. code-block:: bash27 salt '*' win_dns_client.get_dns_servers 'Local Area Connection'28 '''29 # remove any escape characters30 interface = interface.split('\\')31 interface = ''.join(interface)32 with salt.utils.winapi.Com():33 c = wmi.WMI()34 for iface in c.Win32_NetworkAdapter(NetEnabled=True):35 if interface == iface.NetConnectionID:36 iface_config = c.Win32_NetworkAdapterConfiguration(Index=iface.Index).pop()37 try:38 return list(iface_config.DNSServerSearchOrder)39 except TypeError:40 return []41 log.debug('Interface "{0}" not found'.format(interface))42 return False43def rm_dns(ip, interface='Local Area Connection'):44 '''45 Remove the DNS server from the network interface46 CLI Example:47 .. code-block:: bash48 salt '*' win_dns_client.rm_dns <ip> <interface>49 '''50 cmd = ['netsh', 'interface', 'ip', 'delete', 'dns', interface, ip, 'validate=no']51 return __salt__['cmd.retcode'](cmd, python_shell=False) == 052def add_dns(ip, interface='Local Area Connection', index=1):53 '''54 Add the DNS server to the network interface55 (index starts from 1)56 Note: if the interface DNS is configured by DHCP, all the DNS servers will57 be removed from the interface and the requested DNS will be the only one58 CLI Example:59 .. code-block:: bash60 salt '*' win_dns_client.add_dns <ip> <interface> <index>61 '''62 servers = get_dns_servers(interface)63 # Return False if could not find the interface64 if servers is False:65 return False66 # Return true if configured67 try:68 if servers[index - 1] == ip:69 return True70 except IndexError:71 pass72 # If configured in the wrong order delete it73 if ip in servers:74 rm_dns(ip, interface)75 cmd = ['netsh', 'interface', 'ip', 'add', 'dns',76 interface, ip, 'index={0}'.format(index), 'validate=no']...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!