I am having two Ethernet card installed on my PC, thus having two interfaces. These two interfaces are connected to Router's two interfaces. Such that:
PC_INT_A --- Network1 ---> ROUTER_INT_1
PC_INT_B --- Network2 ---> ROUTER_INT_2
All the interfaces are fully configured for IPv6 communication. Ping6 is working well through command line.
But when I am trying to send through scapy, while both the networks are connected. I am able to send only first interface in the code. Or I have to disconnect one particular network.
See Below code:
def ns_with_ll(src, dst):
base = IPv6(src=src, dst=dst, nh=58, hlim=255)
ns = ICMPv6ND_NS(tgt=dst)
ll = ICMPv6NDOptSrcLLAddr()
pkt = base / ns / ll
return pkt
if __name__ == '__main__':
SRC_A = 'IPV6_ADDR_OF_ETH0'
SRC_B = 'IPV6_ADDR_OF_ETH1'
DST_1 = 'IPV6_ADDR_ROUTER_INT_1'
DST_2 = 'IPV6_ADDR_ROUTER_INT_2'
ns_a = ns_with_ll(SRC_A, DST_1)
ns_b = ns_with_ll(SRC_B, DST_2)
sr(ns_a, iface='eth0')
sr(ns_b, iface='eth1')
The above code gives me output as follows:
Begin emission:
*Finished sending 1 packets.
Received 1 packets, got 1 answers, remaining 0 packets
Begin emission:
Finished sending 1 packets.
..........................................................................
It keeps waiting for the answer from eth1
interface.
If i change the order of packet sending in code like I am sending packet to eth1
first. I receive answer from eth1
and it keeps waiting for answer from eth0
.
I also check in wireshark, but I do not receive any packet for the second interface.
I have also tried same with sending ICMPv6EchoRequest
, it behaves in the same way.
Can somebody tell me, how to simultaneously work with multiple networks using scapy. I am using scapy version 2.4.2 with python 3.4?
Hi!
In Scapy, you have two ways of sending packets. The "layer 3 way", which uses the internal routing table (conf.route
), and the "layer 2 way", which sends a packet on a given interface (conf.iface
being the default).
send()
is a "layer 3" function (so it relies on Scapy's routing table), while sendp()
is a "layer 2" function (it has an iface=
optional parameter and will use conf.iface
by default). That's the same for sr()
and srp()
.
So in your case, using srp()
instead of sr()
and providing the Ether()
layer should work:
if __name__ == '__main__':
[...]
srp(Ether() / ns_a, iface='eth0')
srp(Ether() / ns_b, iface='eth1')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With