Пример #1
0
def _scapy_iface(iface):
    from scapy.layers.l2 import get_if_hwaddr
    if IS_WINDOWS:
        from scapy.arch.windows import get_windows_if_list
        interfaces = get_windows_if_list()
        for i in interfaces:
            if any(iface in i[x] for x in ['name', 'netid', 'description', 'win_index']):
                return i['mac']
    # Do not put an 'else' here!
    return get_if_hwaddr(iface)
Пример #2
0
 def send_packet(self, tcp_packet):
     with self._lock:
         interface = Route().route(tcp_packet.destination_ip)[0]
         ip_packet = IPPacket(source_ip_addr=tcp_packet.source_ip,
                              destination_ip_addr=tcp_packet.destination_ip,
                              payload=tcp_packet.serialize())
         ethernet_packet = EthernetPacket(
             source_mac=get_if_hwaddr(interface),
             destination_mac=getmacbyip(tcp_packet.destination_ip),
             protocol=ETH_P_IP,
             payload=ip_packet.serialize())
         self.interface_socket.sendto(
             ethernet_packet.serialize(),
             (Route().route(tcp_packet.destination_ip)[0], ETH_P_ALL))
Пример #3
0
def unpack_iface(iface: str) -> tuple:
    """ Return tuple(IP: str, MAC: str) """
    return l2.get_if_addr(iface), l2.get_if_hwaddr(iface)