Best Python code snippet using fMBT_python
run_attacks.py
Source:run_attacks.py
...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)...
start.py
Source:start.py
...129 return gw130# Start the routing daemons131# When a I2RS daemon is ready add it to the routers you want it to run, probably run:132# router.cmd("/usr/lib/quagga/i2rsd -f conf/i2rsd-%s.conf -d -i /tmp/i2rsd-%s.pid > logs/%s-i2rsd-stdout 2>&1" % (router.name, router.name, router.name))133# router.waitOutput()134def startRouting(router):135 if router.name == "r010_1":136 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))137 router.waitOutput()138 router.cmd("/usr/lib/quagga/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)139 router.waitOutput()140 router.cmd("/usr/lib/quagga/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgpd-%s.pid > logs/%s-bgpd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)141 router.waitOutput()142 log("Starting zebra and ospfd and bgpd on %s" % router.name)143 elif router.name == "r010_2":144 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))145 router.waitOutput()146 router.cmd("/usr/lib/quagga/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)147 router.waitOutput()148 log("Starting zebra and ospfd on %s" % router.name)149 elif router.name == "r010_3":150 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))151 router.waitOutput()152 router.cmd("/usr/lib/quagga/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)153 router.waitOutput()154 log("Starting zebra and ospfd on %s" % router.name)155 elif router.name == "r010_4":156 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))157 router.waitOutput()158 router.cmd("/usr/lib/quagga/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)159 router.waitOutput()160 log("Starting zebra and ospfd on %s" % router.name)161 elif router.name == "r010_5":162 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))163 router.waitOutput()164 router.cmd("/usr/lib/quagga/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)165 router.waitOutput()166 log("Starting zebra and ospfd on %s" % router.name)167 elif router.name == "r100_1":168 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))169 router.waitOutput()170 router.cmd("/usr/lib/quagga/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgpd-%s.pid > logs/%s-bgpd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)171 router.waitOutput()172 log("Starting zebra and bgpd on %s" % router.name)173 elif router.name == "r200_1":174 router.cmd("/usr/lib/quagga/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))175 router.waitOutput()176 router.cmd("/usr/lib/quagga/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgpd-%s.pid > logs/%s-bgpd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)177 router.waitOutput()178 log("Starting zebra and bgpd on %s" % router.name)179 else:180 log("WARNING: No routing deamon configured for %s." % (router.name))181 return182def main():183 os.system("rm -f /tmp/r*.log /tmp/r*.pid logs/*")184 os.system("mn -c >/dev/null 2>&1")185 os.system("killall -9 zebra bgpd ospfd > /dev/null 2>&1")186 net = Mininet(topo=SimpleTopo(), switch=Router)187 net.start()188 for router in net.switches:189 router.cmd("sysctl -w net.ipv4.ip_forward=1")190 router.waitOutput()191 log("Waiting %d seconds for sysctl changes to take effect..."192 % args.sleep)193 sleep(args.sleep)194 # initialize routing daemons195 for router in net.switches:196 startRouting(router)197 # set hosts IP and gateways198 for host in net.hosts:199# using "ip cmd" leaves 10.0.0.x/8 ip on the interface of the hosts and 10.0.0.0/8 on the routing table200# host.cmd("ip a add %s dev %s-eth0" % (getIP(host.name), host.name))201# host.cmd("ip r add default via %s" % (getGateway(host.name)))202 host.cmd("ifconfig %s-eth0 %s" % (host.name, getIP(host.name)))203 host.cmd("route add default gw %s" % (getGateway(host.name)))204 CLI(net)...
run-trial.py
Source:run-trial.py
...30 self.addLink(LTE, s2)31 self.addLink(s2, receiver)32def set_all_IP(net, sender, LTE, receiver):33 sender.sendCmd('ifconfig sender-eth0 10.0.1.1 netmask 255.255.255.0')34 sender.waitOutput()35 LTE.sendCmd('ifconfig LTE-eth0 up')36 LTE.waitOutput()37 LTE.sendCmd('ifconfig LTE-eth1 up')38 LTE.waitOutput()39 receiver.sendCmd('ifconfig receiver-eth0 10.0.1.2 netmask 255.255.255.0')40 receiver.waitOutput()41 sender.sendCmd('echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6')42 sender.waitOutput()43 LTE.sendCmd('echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6')44 LTE.waitOutput()45 receiver.sendCmd('echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6')46 receiver.waitOutput()47def display_routes(net, sender, LTE, receiver):48 print 'sender route...'49 sender.sendCmd('route -n')50 print sender.waitOutput()51 print 'LTE route...'52 LTE.sendCmd('route -n')53 print LTE.waitOutput()54 print 'receiver route...'55 receiver.sendCmd('route -n')56 print receiver.waitOutput()57def run_cellsim(LTE):58 LTE.sendCmd('/home/ubuntu/multisend/sender/cellsim-setup.sh LTE-eth0 LTE-eth1')59 LTE.waitOutput()60 print "Running cellsim (this will take a few minutes)..."61 LTE.sendCmd('/home/ubuntu/multisend/sender/cellsim-runner.sh')62 LTE.waitOutput()63 print "done."64def run_datagrump(sender, receiver):65 print "Running datagrump-receiver...",66 receiver.sendCmd('/home/ubuntu/datagrump/datagrump-receiver 9000 >/tmp/receiver-stdout 2>/tmp/receiver-stderr &')67 receiver.waitOutput()68 print "done."69 print "Running datagrump-sender...",70 sender.sendCmd('/home/ubuntu/datagrump/datagrump-sender 10.0.1.2 9000 debug >/tmp/sender-stdout 2>/tmp/sender-stderr &')71 sender.waitOutput()72 print "done."73def print_welcome_message():74 print "####################################################################"75 print "# #"76 print "# 6.829 PS 2 Emulated Network Test #"77 print "# #"78 print "# running sender <=> cellsim <=> receiver #"79 print "# #"80 print "# Debug output in /tmp/{sender,receiver,cellsim}-{stdout,stderr} #"81 print "# #"82 print "####################################################################"83 print84def run_cellsim_topology():85 print_welcome_message()...
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!!