How to use get_time_taken method in stestr

Best Python code snippet using stestr_python

run_attacks.py

Source:run_attacks.py Github

copy

Full Screen

...5from mininet.link import TCLink6from mininet.util import dumpNodeConnections7import time8OUTPUT_DIR = "./plots"9def get_time_taken(filename):10 time_taken = 011 with open(filename, "r") as f:12 lines = f.readlines()13 for line in lines:14 typ, time, data_size = line.split(",")15 if typ == "time_taken":16 time_taken = time17 break18 return time_taken19def build_parser():20 parser = argparse.ArgumentParser(description="Attack plot generator")21 parser.add_argument(22 "--output",23 dest="output_dir",24 default=OUTPUT_DIR,25 help="Directory to store output plots.",26 )27 parser.add_argument(28 "--delay",29 dest="link_delay",30 type=int,31 default=250,32 help="Link delay in ms (default is 250ms).",33 )34 parser.add_argument(35 "--data-size",36 dest="data_size",37 type=int,38 default=60,39 help="Amount of data to be sent from sender side (in kB).",40 )41 parser.add_argument(42 "--num-attack",43 dest="num_attack",44 type=int,45 default=50,46 help="Number of ACK packets to perform attacks.",47 )48 parser.add_argument(49 "--opt-interval",50 dest="opt_interval",51 type=int,52 default=20,53 help="Time interval between sending optimistic ACKs\54 in ms (used in Optimistic ACKing attack only).",55 )56 return parser57def main():58 parser = build_parser()59 args = parser.parse_args()60 # Build topology61 topo = mn.StarTopo()62 net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)63 net.start()64 # Dumps network topology65 dumpNodeConnections(net.hosts)66 # Performs a basic all pairs ping test to check connectivity67 drop_rate = net.pingAll()68 if drop_rate > 0:69 print("Reachability test failed!! Please restart.")70 return71 # Note: for the following TCP communication,72 # always start the receiver side first!73 data_size, num_attack = args.data_size, args.num_attack74 opt_interval, output_dir = args.opt_interval, args.output_dir75 h1 = net.get("h1")76 h2 = net.get("h2")77 h3 = net.get("h3")78 h4 = net.get("h4")79 h5 = net.get("h5")80 h6 = net.get("h6")81 h7 = net.get("h7")82 h8 = net.get("h8")83 h9 = net.get("h9")84 h10 = net.get("h10")85 # RTT = 4 * link_delay86 rtt = 4 * args.link_delay87 print("Round-trip delay is %.1f secs." % (rtt / 1000.0))88 # sleep 2s to clean up packets in the network89 time.sleep(2.0)90 command = ""91 for i in range(2, 11):92 command += (93 "python reno.py --role sender --host h1 --target h%d --rtt %d --limit %d & "94 % (i, rtt, data_size)95 )96 # First, record a normal TCP communication97 print("Starting normal TCP connection...")98 start_time = time.time()99 h2.sendCmd("python reno.py --role receiver --host h2")100 h3.sendCmd("python reno.py --role receiver --host h3")101 h4.sendCmd("python reno.py --role receiver --host h4")102 h5.sendCmd("python reno.py --role receiver --host h5")103 h6.sendCmd("python reno.py --role receiver --host h6")104 h7.sendCmd("python reno.py --role receiver --host h7")105 h8.sendCmd("python reno.py --role receiver --host h8")106 h9.sendCmd("python reno.py --role receiver --host h9")107 h10.sendCmd("python reno.py --role receiver --host h10")108 h1.sendCmd(command[:-3])109 h3.waitOutput()110 h4.waitOutput()111 h5.waitOutput()112 h6.waitOutput()113 h7.waitOutput()114 h8.waitOutput()115 h9.waitOutput()116 h10.waitOutput()117 h2.waitOutput()118 h1.waitOutput()119 normal_time = time.time() - start_time120 print("Normal TCP connection done! (%.2f sec)" % (normal_time))121 norm_attacker_time = get_time_taken("logs/h2_log.txt")122 norm_h3_time = get_time_taken("logs/h3_log.txt")123 norm_h4_time = get_time_taken("logs/h4_log.txt")124 norm_h5_time = get_time_taken("logs/h5_log.txt")125 norm_h6_time = get_time_taken("logs/h6_log.txt")126 norm_h7_time = get_time_taken("logs/h7_log.txt")127 norm_h8_time = get_time_taken("logs/h8_log.txt")128 norm_h9_time = get_time_taken("logs/h9_log.txt")129 norm_h10_time = get_time_taken("logs/h10_log.txt")130 time.sleep(2.0)131 # ACK Division attack plot132 print("Starting ACK Division attack...")133 start_time = time.time()134 h2.sendCmd("python attacker.py --host h2 --attack div --num %d" % num_attack)135 h3.sendCmd("python reno.py --role receiver --host h3")136 h4.sendCmd("python reno.py --role receiver --host h4")137 h5.sendCmd("python reno.py --role receiver --host h5")138 h6.sendCmd("python reno.py --role receiver --host h6")139 h7.sendCmd("python reno.py --role receiver --host h7")140 h8.sendCmd("python reno.py --role receiver --host h8")141 h9.sendCmd("python reno.py --role receiver --host h9")142 h10.sendCmd("python reno.py --role receiver --host h10")143 h1.sendCmd(command[:-3])144 h3.waitOutput()145 h4.waitOutput()146 h5.waitOutput()147 h6.waitOutput()148 h7.waitOutput()149 h8.waitOutput()150 h9.waitOutput()151 h10.waitOutput()152 h2.waitOutput()153 h1.waitOutput()154 h2.cmd("mv attack_log.txt logs/div_attack_log.txt")155 division_time = time.time() - start_time156 print("ACK Division attack done! (%.2f sec)" % (division_time))157 div_attacker_time = get_time_taken("logs/div_attack_log.txt")158 div_h3_time = get_time_taken("logs/h3_log.txt")159 div_h4_time = get_time_taken("logs/h4_log.txt")160 div_h5_time = get_time_taken("logs/h5_log.txt")161 div_h6_time = get_time_taken("logs/h6_log.txt")162 div_h7_time = get_time_taken("logs/h7_log.txt")163 div_h8_time = get_time_taken("logs/h8_log.txt")164 div_h9_time = get_time_taken("logs/h9_log.txt")165 div_h10_time = get_time_taken("logs/h10_log.txt")166 time.sleep(2.0)167 # DupACK Spoofing attack plot168 print("Starting DupACK Spoofing attack...")169 start_time = time.time()170 h2.sendCmd("python attacker.py --host h2 --attack dup --num %d" % num_attack)171 h3.sendCmd("python reno.py --role receiver --host h3")172 h4.sendCmd("python reno.py --role receiver --host h4")173 h5.sendCmd("python reno.py --role receiver --host h5")174 h6.sendCmd("python reno.py --role receiver --host h6")175 h7.sendCmd("python reno.py --role receiver --host h7")176 h8.sendCmd("python reno.py --role receiver --host h8")177 h9.sendCmd("python reno.py --role receiver --host h9")178 h10.sendCmd("python reno.py --role receiver --host h10")179 h1.sendCmd(command[:-3])180 h3.waitOutput()181 h4.waitOutput()182 h5.waitOutput()183 h6.waitOutput()184 h7.waitOutput()185 h8.waitOutput()186 h9.waitOutput()187 h10.waitOutput()188 h2.waitOutput()189 h1.waitOutput()190 h2.cmd("mv attack_log.txt logs/dup_attack_log.txt")191 duplicate_time = time.time() - start_time192 print("DupACK Spoofing attack done! (%.2f sec)" % (duplicate_time))193 dup_attacker_time = get_time_taken("logs/dup_attack_log.txt")194 dup_h3_time = get_time_taken("logs/h3_log.txt")195 dup_h4_time = get_time_taken("logs/h4_log.txt")196 dup_h5_time = get_time_taken("logs/h5_log.txt")197 dup_h6_time = get_time_taken("logs/h6_log.txt")198 dup_h7_time = get_time_taken("logs/h7_log.txt")199 dup_h8_time = get_time_taken("logs/h8_log.txt")200 dup_h9_time = get_time_taken("logs/h9_log.txt")201 dup_h10_time = get_time_taken("logs/h10_log.txt")202 time.sleep(2.0)203 # Optimistic ACKing attack plot204 print("Starting Optimistic ACKing attack...")205 start_time = time.time()206 h2.sendCmd(207 "python attacker.py --host h2 --attack opt --num %d --interval %d"208 % (num_attack, opt_interval)209 )210 h3.sendCmd("python reno.py --role receiver --host h3")211 h4.sendCmd("python reno.py --role receiver --host h4")212 h5.sendCmd("python reno.py --role receiver --host h5")213 h6.sendCmd("python reno.py --role receiver --host h6")214 h7.sendCmd("python reno.py --role receiver --host h7")215 h8.sendCmd("python reno.py --role receiver --host h8")216 h9.sendCmd("python reno.py --role receiver --host h9")217 h10.sendCmd("python reno.py --role receiver --host h10")218 h1.sendCmd(command[:-3])219 h3.waitOutput()220 h4.waitOutput()221 h5.waitOutput()222 h6.waitOutput()223 h7.waitOutput()224 h8.waitOutput()225 h9.waitOutput()226 h10.waitOutput()227 h2.waitOutput()228 h1.waitOutput()229 h2.cmd("mv attack_log.txt logs/opt_attack_log.txt")230 optimistic_time = time.time() - start_time231 print("Optimistic ACKing attack done! (%.2f sec)" % (optimistic_time))232 opt_attacker_time = get_time_taken("logs/opt_attack_log.txt")233 opt_h3_time = get_time_taken("logs/h3_log.txt")234 opt_h4_time = get_time_taken("logs/h4_log.txt")235 opt_h5_time = get_time_taken("logs/h5_log.txt")236 opt_h6_time = get_time_taken("logs/h6_log.txt")237 opt_h7_time = get_time_taken("logs/h7_log.txt")238 opt_h8_time = get_time_taken("logs/h8_log.txt")239 opt_h9_time = get_time_taken("logs/h9_log.txt")240 opt_h10_time = get_time_taken("logs/h10_log.txt")241 print(242 str(num_attack)243 + ","244 + str(normal_time)245 + ","246 + str(division_time)247 + ","248 + str(duplicate_time)249 + ","250 + str(optimistic_time)251 + ","252 + str(data_size * 1000)253 )254 with open("data.txt", "a+") as f:...

Full Screen

Full Screen

subscan.py

Source:subscan.py Github

copy

Full Screen

...19 "scanEngine.EngineType", on_delete=models.CASCADE, blank=True, null=True20 )21 def get_completed_ago(self):22 if self.stop_scan_date:23 return get_time_taken(timezone.now(), self.stop_scan_date)24 def get_total_time_taken(self):25 if self.stop_scan_date:26 return get_time_taken(self.stop_scan_date, self.start_scan_date)27 def get_elapsed_time(self):28 return get_time_taken(timezone.now(), self.start_scan_date)29 def get_task_name_str(self):30 if self.dir_file_fuzz:31 return "Directory and File fuzzing"32 elif self.port_scan:33 return "Port Scan"34 elif self.fetch_url:35 return "Endpoint Gathering"36 elif self.vulnerability_scan:37 return "Vulnerability Scan"38 elif self.osint:39 return "OSINT"40 else:...

Full Screen

Full Screen

F.py

Source:F.py Github

copy

Full Screen

...3 def start(self):4 self.start_time = time.time()5 def stop(self):6 self.stop_time = time.time()7 def get_time_taken(self):8 return self.stop_time - self.start_time9class ContextTimer(Timer):10 def __enter__(self):11 print("Inside enter...")12 self.start()13 name= 'ravi'14 return name15 def __exit__(self, a,b,c):16 print ('inside exist')17 self.stop()18 print self.get_time_taken()19 return 'ranjan'20class person:21 pass22if __name__ == "__main__":23 # t = Timer()24 # t.start()25 # time.sleep(5)26 # t.stop()27 # print ('Time taken', t.get_time_taken())28 with ContextTimer() as a:29 for i in range(10000):30 for j in range(1000):31 s = 1 * j * 1.0...

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