Best Python code snippet using autotest_python
tcpdump_bussiness.py
Source:tcpdump_bussiness.py
...23 print 'å¤ä»½remote主æºçæä»¶%s%sæå'%(dir,filename)24 #卿¬å°æå¼ä¸è½½çæä»¶ï¼æ¸
空åå
容并åå
¥éè¦æ°å
容25 public_control.modify_file('./data/%s'%filename,content)26 #éè¿scpåä¼ è¾ç»remote主æº27 tcpdump_control.scp_to_remote('./data/%s'%filename,d[0],d[1],d[2],dir)28 print 'ä¿®æ¹remoteä¸»æºæä»¶%s%sæå'%(dir,filename)29 #å 餿¬å°å°æä»¶30 subprocess.call('rm -rf ./data/%s'%filename,shell=True)31#æè¿°ï¼æ¬å½æ°å®ç°éè¿è·¯ç±çsshçé»è®¤ipï¼ç¨æ·åï¼å¯ç ç»å½åtcpdumpæåè·¯ç±å¨WANå£çå
32#è¾å
¥ï¼wan-wanæ¥å£çæ¥å£å33#è¾åºï¼å°å
ä¿æçæä»¶åï¼/tmp/wanlog34def capture_wan_packet():35 #è°ç¨sshçé»è®¤ç»å½ipï¼ç¨æ·ååå¯ç 36 d = data.ssh_user()37 tcpdump_control.tcpdump_command(d[1],d[0],d[2],'tcpdump -i eth1 -s0 -w /tmp/wanlog')38 return '/tmp/wanlog'39#æè¿°ï¼æ¬å½æ°å®ç°éè¿è·¯ç±çsshçé»è®¤ipï¼ç¨æ·åï¼å¯ç ç»å½åtcpdumpæåè·¯ç±å¨WANå£çå
40#è¾å
¥ï¼wlan-wlanæ¥å£çæ¥å£å41#è¾åºï¼å°å
ä¿æçæä»¶åï¼/tmp/wlanlog42def capture_wlan_packet():43 #è°ç¨sshçé»è®¤ç»å½ipï¼ç¨æ·ååå¯ç 44 d = data.ssh_user()45 tcpdump_control.tcpdump_command(d[1],d[0],d[2],'tcpdump -i wlan0 -s0 -w /tmp/wlanlog')46 return '/tmp/wlanlog'47###############################################48#以䏿¯æéè¦æå
çæµè¯ç¨ä¾çæµè¯æ¥éª¤49###############################################50#æè¿°ï¼#æè¿°ï¼æµè¯ç¨ä¾100msh0287æµè¯æ¥éª¤----pingæ¥æå
容忮µæ£æ¥51def step_100msh0287(self):52 #ä¿®æ¹é¨æ·è®¤è¯çæ£æ¥é´é为60s53 general_control.set_checkInterval(self,'60')54 general_control.apply(self)55 time.sleep(60)56 #ä¸ä¼ tcpdumpå°è·¯ç±å¨57 #è°ç¨sshçé»è®¤ç»å½ipï¼ç¨æ·ååå¯ç 58 d = data.ssh_user()59 tcpdump_control.scp_to_remote('./data/BHU_tcpdump/tcpdump',d[0],d[1],d[2],'/usr/sbin/')60 tcpdump_control.scp_to_remote('./data/BHU_tcpdump/libpcap.so.1.3',d[0],d[1],d[2],'/usr/lib/')61 #sshç»å½è·¯ç±è¾å
¥tcpdumpæå
62 wanlog = capture_wan_packet()63 #å°æå°çå°å
ä¼ è¾åæ¬å°pc64 tcpdump_control.scp_to_local(d[0],d[1],d[2],wanlog,'./data/')65 #æå¼æ¬å°ä¸è½½çæä»¶ï¼è¯»åæä»¶å
容66 f = open('./data/wanlog')67 log = f.read()68 f.close()69 '''#è·åè·¯ç±ç½å
³ID70 gw = general_control.get_gatewayId(self)71 #è·¯ç±mac72 r_mac = ssh.ssh_cmd2("ifconfig eth0 | grep HWaddr | awk '{print$5}'")73 R_MAC = r_mac.upper()74 #è·¯ç±çæ¬75 r_version = ssh.ssh_cmd2('cat /etc/version/version')76 R_VERSION = r_version.upper()77 #è·¯ç±æ 线mac78 wlan_mac = ssh.ssh_cmd2("ifconfig wlan0 | grep HWaddr | awk '{print$5}'")79 WLAN_MAC = wlan_mac.upper()'''80 #æ£ç¡®çå¿è·³pingä¿¡æ¯å符å¦ä¸81 ping_str1 = 'GET /index/ping/?gw_id='82 #ping_str2 = 'route_mac=%s&route_version=%s&wlan_mac_0=%s'%(R_MAC,R_VERSION,WLAN_MAC)83 if ping_str1 in log:84 #pingä¿¡æ¯å¨logä¿¡æ¯ä¸ï¼è¯´ææå¿è·³ä¿¡æ¯ï¼ç»æèµå¼185 result = 186 else:87 #pingä¿¡æ¯ä¸å¨logä¿¡æ¯ä¸ï¼è¯´ææ²¡æå¿è·³ä¿¡æ¯ï¼ç»æèµå¼088 result = 089 #ç»æè¿åç»å½æ°90 return result91#æè¿°ï¼#æè¿°ï¼æµè¯ç¨ä¾100msh0286æµè¯æ¥éª¤----ååºå管çè·¯ç±å¨åè½æ£æ¥92def step_100msh0286(self):93 #ä¿®æ¹è¯·æ±ç®¡çæ¥å£çæ¶é´é´é为1åé94 content = ['0 2 * * * /bin/rand_upgrade_msh\n',95 '0 4 * * * /sbin/rand_reboot\n',96 '0 6 * * * /etc/init.d/sysntpd restart\n',97 '*/1 * * * * /sbin/get_manage\n',98 '0 1 * * * /sbin/cwifi_pwd\n']99 modify_remote_file('/etc/crontabs/','root',content)100 #éå¯è·¯ç±å®æ¶æºå¶101 ssh.ssh_cmd2('/etc/init.d/cron restart')102 time.sleep(10)103 #ä¸ä¼ tcpdumpå°è·¯ç±å¨104 #ä¸ä¸ªç¨ä¾å·²ç»ä¸ä¼ äºï¼è¿éå°±ä¸åä¸ä¼ äº105 d = data.ssh_user()106 #tcpdump_control.scp_to_remote('./data/BHU_tcpdump/tcpdump',d[0],d[1],d[2],'/usr/sbin/')107 #tcpdump_control.scp_to_remote('./data/BHU_tcpdump/libpcap.so.1.3',d[0],d[1],d[2],'/usr/lib/')108 #sshç»å½è·¯ç±è¾å
¥tcpdumpæå
109 wanlog = capture_wan_packet()110 #å°æå°çå°å
ä¼ è¾åæ¬å°pc111 tcpdump_control.scp_to_local(d[0],d[1],d[2],wanlog,'./data/')112 #æå¼æ¬å°ä¸è½½çæä»¶ï¼è¯»åæä»¶å
容113 f = open('./data/wanlog')114 log = f.read()115 f.close()116 '''#è·åè·¯ç±ç½å
³ID117 gw = general_control.get_gatewayId(self)118 #è·¯ç±mac119 r_mac = ssh.ssh_cmd2("ifconfig eth0 | grep HWaddr | awk '{print$5}'")120 R_MAC = r_mac.upper()121 #è·¯ç±çæ¬...
sync_data.py
Source:sync_data.py
...10 if dry_run:11 cmd += ' --dry-run'12 print cmd13 check_call(cmd, shell=True)14def scp_to_remote(local, remote):15 cmd = 'scp -r %s %s' % (local, remote)16 check_call(cmd, shell=True)17def tar_scp_to_remote(local, remote, dry_run=False):18 tar_file = local + '.tar'19 tar_cmd = 'tar -cvf %s %s' % (tar_file, local)20 print tar_cmd21 check_call(tar_cmd, shell=True)22 scp_to_remote(tar_file, remote)23if __name__ == '__main__':...
Check out the latest blogs from LambdaTest on this topic:
Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Mobile App Testing Tutorial.
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
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!!