How to use get_ipaddrs method in avocado

Best Python code snippet using avocado_python

internet.py

Source:internet.py Github

copy

Full Screen

1# -*- coding:utf-8 -*-2import time3import logging4import configparser5import paramiko6import json7import time8import re9import os10import sys11from selenium .webdriver.common.action_chains import ActionChains12class internet:13 def __call__(self,ipaddr, netmask, gateway, dns1, dns2):14 ipaddr = ipaddr15 netmask = netmask16 gateway = gateway17 dns1 = dns118 dns2 = dns219 ####选择进入某页面进行设置####20 def setup_choose(self, driver, choose):21 time.sleep(2)22 try:23 logging.info("try enter router setup")24 driver.find_element_by_link_text(u"路由设置").click()25 time.sleep(5)26 if choose == 1:27 logging.info("try click wifi setup ")28 driver.find_element_by_link_text(u"WIFI设置").click()29 time.sleep(2)30 return 131 if choose == 2:32 logging.info("try click internet steup ")33 driver.find_element_by_link_text(u"互联网设置").click()34 time.sleep(2)35 return 236 if choose == 3:37 logging.info("try click wireless repeater setup ")38 driver.find_element_by_link_text(u"无线中继").click()39 return 340 if choose == 4:41 logging.info("try click LAN setup")42 driver.find_element_by_link_text(u"局域网设置").click()43 return 444 if choose == 5:45 logging.info("try click system setup ")46 driver.find_element_by_link_text(u"系统设置").click()47 return 548 except Exception as e:49 driver.get_screenshot_as_file(os.path.dirname(os.getcwd())+"/errorpng/setup_choose-%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime()))50 logging.error("=== enter router setup error === %s", e)51 return 052 finally:53 pass54 ###设置静态IP###55 def set_statics(self, driver, test_statics, ipaddr, netmask, gateway, dns1, dns2):56 logging.info('Try SET Static')57 time.sleep(2)58 try:59 driver.find_element_by_id("dropdownMenu1").click()60 time.sleep(2)61 ###静态IP元素定位###62 set_internetstatic = driver.find_element_by_id("set_internetstatic")63 ActionChains(driver).click(set_internetstatic).perform()64 time.sleep(2)65 logging.info("set static ip")66 driver.find_element_by_id("set_internet_ipaddr").clear()67 driver.find_element_by_id("set_internet_ipaddr").send_keys(ipaddr)68 logging.info("set static gateway")69 driver.find_element_by_id("set_internet_gateway").clear()70 driver.find_element_by_id("set_internet_gateway").send_keys(gateway)71 if test_statics == 1:72 logging.info("test static fill")73 else:74 logging.info("test full set static")75 driver.find_element_by_id("set_internet_netmask").clear()76 driver.find_element_by_id("set_internet_netmask").send_keys(netmask)77 time.sleep(1)78 driver.find_element_by_id("set_internet_dns1").clear()79 driver.find_element_by_id("set_internet_dns1").send_keys(dns1)80 time.sleep(1)81 driver.find_element_by_id("set_internet_dns2").clear()82 driver.find_element_by_id("set_internet_dns2").send_keys(dns2)83 time.sleep(1)84 time.sleep(1)85 driver.find_element_by_id("btn_staticButton").click()86 time.sleep(3)87 driver.find_element_by_xpath("/html/body/div[7]/div/div/div[3]/div/div[2]").click()88 time.sleep(1)89 logging.info('SET Static Success')90 return 191 except Exception as e:92 driver.get_screenshot_as_file(os.path.dirname(os.getcwd())+"/errorpng/set_statics-%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime()))93 logging.error('====Set Static error==== %s' %e)94 return 095 finally:96 pass97 ###获取静态IP设置###98 def get_static(self, driver):99 time.sleep(1)100 try:101 get_ipaddr = "return document.getElementById('set_internet_ipaddr').value;"102 get_ipaddrs=driver.execute_script(get_ipaddr)103 logging.info('Get static IP = %s' % get_ipaddrs)104 get_netmask = "return document.getElementById('set_internet_netmask').value;"105 get_netmasks=driver.execute_script(get_netmask)106 logging.info('Get static NETMASK = %s' % get_netmasks)107 get_gateway = "return document.getElementById('set_internet_gateway').value;"108 get_gateways = driver.execute_script(get_gateway)109 logging.info('Get static Gateway = %s' % get_gateways)110 get_dns1 = "return document.getElementById('set_internet_dns1').value;"111 get_dns1s = driver.execute_script(get_dns1)112 logging.info('Get static DNS1 = %s' % get_dns1s)113 get_dns2 = "return document.getElementById('set_internet_dns2').value;"114 get_dns2s = driver.execute_script(get_dns2)115 logging.info('Get static DNS2 = %s' % get_dns2s)116 result = 0117 if get_ipaddrs == ipaddr:118 logging.info(' %s = %s ' % (get_ipaddrs, ipaddr))119 result = result + 1120 if get_netmasks == netmask:121 logging.info('')122 result = result + 1123 if get_gateways == gateway:124 logging.info('%s = %s' % (get_gateway, gateway))125 result = result + 1126 if get_dns1s == dns1:127 logging.info('%s = %s ' % (get_dns1s, dns1))128 result = result + 1129 if get_dns2s == dns2:130 logging.info('%s = %s ' % (get_dns2s,dns2))131 result = result + 1132 return result133 except Exception as e:134 driver.get_screenshot_as_file(os.path.dirname(os.getcwd())+"/errorpng/GetStatic-%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime()))135 logging.error('==== GET Static error ==== %s' %e)...

Full Screen

Full Screen

get_ips.py

Source:get_ips.py Github

copy

Full Screen

...22def fatal_query(e):23 #return print(e)24 pass25@backoff.on_exception(backoff.expo, (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers), max_tries=3, giveup=fatal_query)26def get_ipaddrs(domain):27 dns_result = dnsResolver.query(domain, 'A')28 for data in dns_result:29 ips.add(data)30for el in d['settings']['servers']['server']:31 o = urlparse(el['@url'])32 domain = o.netloc.split(':')[0]33 try:34 socket.inet_aton(domain)35 ips.add(domain)36 except socket.error:37 pool.apply_async(get_ipaddrs, (domain,))38pool.close()39pool.join()40for i in ips:...

Full Screen

Full Screen

telnet.py

Source:telnet.py Github

copy

Full Screen

...13 tn.write(b"migrate -d tcp:192.168.3.17:4449")14 tn.write(b"quit\n")15"""16#!/bin/bash17get_ipaddrs() {18 echo 19 ifconfig -a |20 grep inet[^6] | 21 sed 's/.*inet[^6][^0-9]*\([0-9.]*\)[^0-9]*.*/\1/' | 22 grep -v '^127\.'23}24ip=`get_ipaddrs`25telnet $ip 444426"""27"""28> info status29VM status: running30> migrate_set_speed 1g31> migrate -d tcp:192.168.3.17:4449...

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 avocado 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