pynetwork / pypcap

pypcap - python libpcap module, forked from code.google.com/p/pypcap
Other
299 stars 75 forks source link

Can't find referencs for pcap.py, import pcap ImportError: DLL load failed: can't find the module. #75

Closed atirelli3 closed 6 years ago

atirelli3 commented 6 years ago
import getopt, sys
import dpkt, pcap
import socket
import struct
import binascii
import textwrap

def main():
    # Get host
    host = socket.gethostbyname(socket.gethostname())
    print('IP: {}'.format(host))

    name = None
    pc = pcap.pcap(name)
    decode = { pcap.DLT_LOOP:dpkt.loopback.Loopback,
               pcap.DLT_NULL:dpkt.loopback.Loopback,
               pcap.DLT_EN10MB:dpkt.ethernet.Ethernet }[pc.datalink()]
    try:
        print('listening on %s: %s' % (pc.name, pc.filter))
        for ts, pkt in pc:
            pkt = str(decode(pkt))
            dest_mac, src_mac, eth_proto, data = ethernet_frame(pkt)

            print('\nEthernet Frame:')
            print("Destination MAC: {}".format(dest_mac))
            print("Source: {}".format(src_mac))
            print("Protocol: {}".format(eth_proto))
    except KeyboardInterrupt:
        nrecv, ndrop, nifdrop = pc.stats()
        print('\n%d packets received by filter' % nrecv)
        print('%d packets dropped by kernel' % ndrop)

# Unpack ethernet frame
def ethernet_frame(data):
    dest_mac, src_mac, proto = struct.unpack('!6s6s2s', data[:14])
    return binascii.hexlify(dest_mac), binascii.hexlify(src_mac), binascii.hexlify(proto), data[14:]

if __name__ == '__main__':
    main()

C:\Python34\python.exe C:/Users/Tirel/PycharmProjects/demo_Sniffer/sniffer.py
Traceback (most recent call last):
  File "C:/Users/Tirel/PycharmProjects/demo_Sniffer/sniffer.py", line 2, in <module>
    import dpkt, pcap
ImportError: DLL load failed: can't find the module.

I have install pypcap in python 3.4 on Windows 10

PyCharm see the path of pcap C:\Python34\Lib\site-packages\pypcap-1.2.2-py3.4-win-amd64.egg, but when i run it he gave me this error and he can see the method of the class

Can't find referencs for pcap.py import pcap ImportError: DLL load failed: can't find the module.

Sorry for my bad english and thank you