Skip to content

Commit 88daaf7

Browse files
committed
simple it
1 parent 622eb22 commit 88daaf7

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

andpp.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import fire
22
import os
3-
from scapy.all import sniff, sendp, Ether, IPv6, ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr
3+
from scapy.all import sniff, sendp, Ether, IPv6, ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, get_if_hwaddr
44

5-
is_strict_match="STRICT" in os.environ
65
ns_counter=0
76
def dump_nd_so(x):
87
global ns_counter
@@ -22,21 +21,16 @@ def send_nd_ad_for(x, outer_ether_addr):
2221
sendp(Ether(dst=ether_dst, src=ether_src)/IPv6(version=6, tc=0, fl=0, plen=32, hlim=255, src=x[ICMPv6ND_NS].tgt, dst=x[IPv6].src)/ICMPv6ND_NA(code=0, R=0, S=1, O=1, res=0x0, tgt=x[ICMPv6ND_NS].tgt)/ICMPv6NDOptDstLLAddr(type=2, len=1, lladdr=outer_ether_addr), iface=iface)
2322
return True
2423

25-
def is_expected_nd_so(x, expected_prefix, router_ether_addr):
26-
if is_strict_match:
27-
return x[Ether].src==router_ether_addr and x[ICMPv6ND_NS].tgt.startswith(expected_prefix)
28-
else:
29-
return x[ICMPv6ND_NS].tgt.startswith(expected_prefix)
24+
def is_expected_nd_so(x, expected_prefix):
25+
return x[ICMPv6ND_NS].tgt.startswith(expected_prefix)
3026

31-
def is_expected_nd_ad(x, expected_prefix, router_ether_addr):
32-
if is_strict_match:
33-
return x[Ether].dst==router_ether_addr and x[ICMPv6ND_NA].tgt.startswith(expected_prefix)
34-
else:
35-
return x[ICMPv6ND_NA].tgt.startswith(expected_prefix)
27+
def is_expected_nd_ad(x, expected_prefix):
28+
return x[ICMPv6ND_NA].tgt.startswith(expected_prefix)
3629

37-
def main(outer_iface, outer_ether_addr, router_ether_addr, proxy_net_prefix):
30+
def main(outer_iface, proxy_net_prefix):
31+
outer_ether_addr=get_if_hwaddr(outer_iface)
3832
sniff(filter='icmp6',
39-
lfilter= lambda x: is_expected_nd_so(x, proxy_net_prefix, router_ether_addr) if ICMPv6ND_NS in x else is_expected_nd_ad(x, proxy_net_prefix, router_ether_addr) if ICMPv6ND_NA in x else False,
33+
lfilter= lambda x: is_expected_nd_so(x, proxy_net_prefix) if ICMPv6ND_NS in x else is_expected_nd_ad(x, proxy_net_prefix) if ICMPv6ND_NA in x else False,
4034
prn= lambda x: (dump_nd_so(x),send_nd_ad_for(x, outer_ether_addr))[0] if ICMPv6ND_NS in x else dump_nd_ad(x),
4135
iface=outer_iface)
4236

0 commit comments

Comments
 (0)