Search code examples
pythonmininet

Mininet set IP of host from a python file


I would like to run a python file on the default Mininet host h1, which alters the IP address of h1 and sends data from h1 to other targets. How can I do this? On the Mininet command line, changing the IP address is done as follows: py h1.setIP('Ipaddress').

What I would like is:

h1 run_python_file new_ip

which would change the IP address of h1 to new_ip, create a socket, and send random data to a destination.


Solution

  • You can run a script at host h1 by first navigating to the directory of the script and then running h1 python3 nameOfScript.py. You can think of h1 as a Linux machine, so running a Python script needs to be done via the python3 command. Here is another example:

    *** Starting CLI:
    mininet> h1 python3 hello.py
    hello world
    mininet> 
    

    I created a hello.py script and started Mininet from the same directory by running sudo mn, then I can called the script. You can pass the new_ip argument to the script as per Python's docs.