from scapy.all import ETH_P_IP, ETH_P_IPV6, ETH_P_ALL, ETH_P_ARP
from scapy.all import ETH_P_IP, ETH_P_IPV6, ETH_P_ALL, ETH_P_ARP
from scapy.layers.inet6 import IPv6
__all__ = ['RxQueue', 'TxQueue', 'Interface', 'create_gratuitous_arp_request',
'auto_pad', 'checksum_equal']
from scapy.layers.inet6 import IPv6
__all__ = ['RxQueue', 'TxQueue', 'Interface', 'create_gratuitous_arp_request',
'auto_pad', 'checksum_equal']
Takes string as input and looks for first whole packet in it.
If it finds one, it returns substring from the buf parameter.
Takes string as input and looks for first whole packet in it.
If it finds one, it returns substring from the buf parameter.
- :param buf: string representation of incoming packet buffer.
- :type buf: string
- :return: String representation of first packet in buf.
- :rtype: string
+ :param buf: String representation of incoming packet buffer.
+ :type buf: str
+ :returns: String representation of first packet in buf.
+ :rtype: str
This function is meant to be run in separate subprocess and is in tight
loop reading raw packets from interface passed as parameter.
This function is meant to be run in separate subprocess and is in tight
loop reading raw packets from interface passed as parameter.
"""
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, ETH_P_ALL)
sock.bind((interface_name, ETH_P_ALL))
"""
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, ETH_P_ALL)
sock.bind((interface_name, ETH_P_ALL))
def __init__(self, interface_name):
PacketVerifier.__init__(self, interface_name)
def __init__(self, interface_name):
PacketVerifier.__init__(self, interface_name)
- #self._queue = Queue()
- #self._proc = Process(target=packet_reader, args=(interface_name,
- # self._queue))
- #self._proc.daemon = True
- #self._proc.start()
- #time.sleep(2)
-
- def recv(self, timeout=3, ignore=None):
+ def recv(self, timeout=3, ignore=None, verbose=True):
arrives in given timeout queue.Empty exception will be risen.
:param timeout: How many seconds to wait for next packet.
arrives in given timeout queue.Empty exception will be risen.
:param timeout: How many seconds to wait for next packet.
(rlist, _, _) = select.select([self._sock], [], [], timeout)
if self._sock not in rlist:
return None
pkt = self._sock.recv(0x7fff)
pkt_pad = auto_pad(pkt)
(rlist, _, _) = select.select([self._sock], [], [], timeout)
if self._sock not in rlist:
return None
pkt = self._sock.recv(0x7fff)
pkt_pad = auto_pad(pkt)
# Found the packet in ignore list, get another one
# TODO: subtract timeout - time_spent in here
ignore.remove(ig_pkt)
# Found the packet in ignore list, get another one
# TODO: subtract timeout - time_spent in here
ignore.remove(ig_pkt)
This object is used to send packets over RAW socket on a interface.
:param interface_name: Which interface to send packets from.
This object is used to send packets over RAW socket on a interface.
:param interface_name: Which interface to send packets from.
"""
def __init__(self, interface_name):
PacketVerifier.__init__(self, interface_name)
"""
def __init__(self, interface_name):
PacketVerifier.__init__(self, interface_name)
self.sent_packets.append(pkt)
self.txq.send(pkt)
def recv_pkt(self, timeout=3):
self.sent_packets.append(pkt)
self.txq.send(pkt)
def recv_pkt(self, timeout=3):
return self.rxq.recv(timeout, self.sent_packets)
def create_gratuitous_arp_request(src_mac, src_ip):
return self.rxq.recv(timeout, self.sent_packets)
def create_gratuitous_arp_request(src_mac, src_ip):
return (Ether(src=src_mac, dst='ff:ff:ff:ff:ff:ff') /
ARP(psrc=src_ip, hwsrc=src_mac, pdst=src_ip))
return (Ether(src=src_mac, dst='ff:ff:ff:ff:ff:ff') /
ARP(psrc=src_ip, hwsrc=src_mac, pdst=src_ip))