Reputation: 27
Description:
I'm working on a project using Mininet and Python to simulate an ad-hoc network where nodes communicate using ICMP packets. I’m trying to send ICMP echo requests (ping) directly using Scapy, but I'm encountering issues with sending packets through the bat0 interface.
Problem:
I have set up an ad-hoc network using Mininet with several nodes (sta1, sta2, etc.). Each node runs a Python script that should send ICMP echo requests using Scapy. Here’s a simplified version of my Python code:
from mininet.log import setLogLevel
from mn_wifi.cli import CLI
from mininet.net import Mininet
from scapy.all import IP, ICMP, send
class OpportunisticNode:
def __init__(self, name, net):
self.name = name
self.node = net.get(name)
self.interface = 'bat0' # Interface name used in the network setup
def send_packet(self, dest_ip, message):
src_ip = self.node.IP()
packet = IP(src=src_ip, dst=dest_ip) / ICMP(type='echo-request') / message
print(f"{self.name} sending packet to {dest_ip} with message: {message}")
try:
send(packet, iface=self.interface)
print(f"Packet sent successfully to {dest_ip}")
except Exception as e:
print(f"An error occurred while sending packet: {e}")
if __name__ == '__main__':
setLogLevel('info')
net = Mininet()
# Setup your network here (omitted for brevity)
# Example usage:
nodes = [OpportunisticNode('sta1', net), OpportunisticNode('sta2', net)]
nodes[0].send_packet('192.168.123.2', 'Hello')
CLI(net)
net.stop()
Issue:
When executing nodes[0].send_packet('192.168.123.2', 'Hello'), I encounter the following error:
An error occurred while sending packet: OSError: [Errno 19] No such device
Question:
How can I properly send ICMP packets between Mininet nodes using Scapy, ensuring that the packets are sent through the specified network interface (bat0)?
I appreciate any insights or suggestions on resolving this issue. Thank you!
Upvotes: 0
Views: 47