Best Python code snippet using autotest_python
get_ip_public.py
Source:get_ip_public.py
...27 return ip_public28 except:29 return '0.0.0.0'30 @staticmethod31 def get_ip_local():32 """33 æ¥è¯¢æ¬æºå
ç½IP34 :return:35 """36 try:37 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)38 s.connect(('8.8.8.8', 80))39 ip = s.getsockname()[0]40 finally:41 s.close()42 return ip43if __name__ == '__main__':44 print("å
ç½IPï¼{}".format(IP.get_ip_local()))45 print("å¤ç½IPï¼{}".format(IP.get_ip_public()))46 title= "get_ip_public"47 content = IP.get_ip_public()...
ip_address.py
Source:ip_address.py
2from bs4 import BeautifulSoup3HEADER = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"4 " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",5 }6def get_ip_local(ip):7 resp = requests.get('https://api.binstd.com/ip/location?appkey=yourappkey&ip={}'.format(ip), headers=HEADER)8 print(resp.json())9 html = BeautifulSoup(resp.text, features="lxml")10 tab0_address = html.find('div', {'id': 'tab0_address'})11 result = tab0_address.text12 # ä¸å½ æµæ±ç æå·å¸ é¿éäº13 # ä¸å½ 广西 æ¥å®¾å¸ èé14 # ä¸å½ 广西 æ¥å®¾å¸ 移å¨15 if 'å¸' in result:16 ret = result.strip().split(' ')[2]17 print(ret)18 return ret19if __name__ == '__main__':20 ip = '117.182.155.183'...
get_login_addr.py
Source:get_login_addr.py
...6 page = urllib.urlopen(url)7 html = page.read()8 return html9# string -> string10def get_ip_local(ip):11 html = getHtml("http://www.ip138.com/ips138.asp?ip="+ip+"&action=2")12 u = html.decode('gbk')13 r = u.encode('utf8')14 m=re.search(r'<li>([^li<>]*)</li>',r)15 return m.group(1)16# string -> string | None17def get_ip(str):18 m=re.search(r'([0-9]{1,3}(\.[0-9]{1,3}){3})',str)19 if(m):20 return m.group(1)21 else:22 return None23# -> [string] | []24def get_last_login_ip():25 p = subprocess.Popen('last', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)26 ips = []27 for line in p.stdout.readlines():28 ip = get_ip(line)29 if(ip):30 ips.append(ip)31 return ips32for ip in get_last_login_ip():...
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!!