I need to create a sniff in python using the sniff command, to collect packets entering several interfaces.
When I do it specifying the interfaces with their names with the following command:
sniff(iface=["s1-cpu-eth1","s2-cpu-eth1","s3-cpu-eth1","s4-cpu-eth1"], prn=self.recv)
It works, but if I try to use a variable (this is needed because interfaces can change depending on the context and they can be obtained through a for loop populating a variable), such as:
if_to_sniff="\"s1-cpu-eth1\",\"s2-cpu-eth1\",\"s3-cpu-eth1\",\"s4-cpu-eth1\""
sniff(iface=[if_to_sniff], prn=self.recv)
It doesn't work. I actually tried several ways, but I always get an error saying that the device doesn't exist. How can I do this?
This string looks like CSV format? In which case we can use Python's CSV reader to parse it for us: