With Host Tracker you can have the info you want. Add the module
import pox.host_tracker
Than add a listener in your init`
core.host_tracker.addListenerByName("HostEvent", self._handle_HostEvent) # listen to host_tracker
and later on implement the listener method
def _handle_HostEvent(self, event):
"""
Listen to host_tracker events, fired up every time a host is up or down
To fire up we must issue a pingall from mininet cli.
Args:
event: HostEvent listening to core.host_tracker
Returns: nada
"""
macaddr = event.entry.macaddr.toStr()
port = event.entry.port
# your code here
As you see in the comment unlike the switch event listener which is fired up on start as soon as the switch is connected to the controller, to get host info we must have data running in our network. Issue a ping all in your mininet topology to get all the info. Remeber if you have a custom controller code to flood the packets in the start to get all hosts in your topology.
In order to get IDs of the hosts you should start your mininet topology with the --mac
arg. This way mac addresses of hosts are like 00:00:00:00:01
last 2 numbers represent the ID of the host.