def create_igmp(src_mac, src_ip, group_ip, igmp_type=IGMP_QUERY): """Creates a new IGMP packet based on the given addresses.""" a = Ether(src=src_mac) b = IP(src=src_ip) c = IGMP(type=igmp_type, gaddr=group_ip) c.igmpize(b, a) return a / b / c
def inject_packet(self, iface, dst_mac): ether_part = Ether(src='00:00:00:00:00:00', dst=dst_mac) ip_part = IP(ttl=1, src='0.0.0.0', dst='224.0.0.1') igmp_part = IGMP(type=0x11) igmp_part.mrtime = (self.max_resp_time / 100) & 0xff igmp_part.igmpize(ether=ether_part, ip=ip_part) # Make this IGMP query packet as an unicast packet ether_part.dst = dst_mac sendp(ether_part / ip_part / igmp_part, iface=iface, verbose=False)
def inject_packet(self, iface, dst_mac): ether_part = Ether(src='00:00:00:00:00:00', dst=dst_mac) ip_part = IP(ttl=1, src='0.0.0.0', dst='224.0.0.1') igmp_part = IGMP(type=0x11) igmp_part.mrtime = (self.max_resp_time / 100) & 0xff igmp_part.igmpize(ether=ether_part, ip=ip_part) # Make this IGMP query packet as an unicast packet ether_part.dst = dst_mac sendp(ether_part / ip_part / igmp_part, iface=iface, verbose=False)
def handle_packet(pkt): if IGMP not in pkt or pkt[IGMP].type != 0x11 or pkt[IP].dst != '224.0.0.1': return for channel, watchers in self.channels_being_watched.items(): if not watchers: continue print 'sending ping for %s' % channel ether = Ether(src=get_mac_addr(local_nic)) ip = IP(src=get_ip_address(local_nic)) igmp = IGMP(type=0x16, gaddr=self.config['channels'][channel].split(':')[0]) igmp.igmpize(ip, ether) packet = ether/ip/igmp sendp(packet, iface=local_nic)
def run(self): """Sends IGMP general query packets using the multicast address 224.0.0.1. Received replies are processed by a SniffThread. """ # create IGMP general query packet ether_part = Ether(src=self.mac) ip_part = IP(ttl=self._TTL, src=self.ip, dst=self._IGMP_MULTICAST) igmp_part = IGMP(type=self._IGMP_GENERAL_QUERY) # Called to explicitely fixup associated IP and Ethernet headers igmp_part.igmpize(ether=ether_part, ip=ip_part) while True: sendp(ether_part / ip_part / igmp_part) time.sleep(self._SLEEP)
def run(self): """Sends IGMP general query packets using the multicast address 224.0.0.1. Received replies are processed by a SniffThread. """ # create IGMP general query packet ether_part = Ether(src=self.mac) ip_part = IP(ttl=self._TTL, src=self.ip, dst=self._IGMP_MULTICAST) igmp_part = IGMP(type=self._IGMP_GENERAL_QUERY) # Called to explicitely fixup associated IP and Ethernet headers igmp_part.igmpize(ether=ether_part, ip=ip_part) while True: sendp(ether_part / ip_part / igmp_part) time.sleep(self._SLEEP)
# https://github.com/levigross/Scapy/blob/master/scapy/contrib/igmp.py # The function adjusts the IP header based on conformance rules # and the group address encoded in the IGMP message. # The rules are: # 1. Send General Group Query to 224.0.0.1 (all systems) # 2. Send Leave Group to 224.0.0.2 (all routers) # 3a.Otherwise send the packet to the group address # 3b.Send reports/joins to the group address #!/usr/bin/env python from scapy.all import * from scapy.contrib.igmp import IGMP eth = Ether() # Send General Group Query to 224.0.0.1 (all systems) iph = IP(src='192.168.1.1', dst='224.0.0.1', proto=2) igmp = IGMP(type=0x11, gaddr='0.0.0.0', mrtime=20) igmp.igmpize(iph,eth) sendp(eth/iph/igmp, iface="eth1", count=1) # Send Leave Group to 224.0.0.2 (all routers) iph = IP(src='192.168.1.42', dst='224.0.0.2', proto=2) igmp = IGMP(type=0x17, gaddr='239.0.0.58', mrtime=20) igmp.igmpize(iph,eth) sendp(eth/iph/igmp, iface="eth1", count=1) # Send reports/joins to the group address iph = IP(src='192.168.1.42', dst='239.0.0.59', proto=2) igmp = IGMP(type=0x16, gaddr='239.0.0.59', mrtime=20) igmp.igmpize(iph,eth) sendp(eth/iph/igmp, iface="eth1", count=1)