title: Raw socket packet sniffer in Python 3.6 on Windows
body: <p>I am trying to sniff packets but i am getting strange output and i don't understand the reason..<br> So that's my code <strong>please</strong> help me<br>
  (I'm using Python 3.6 on Windows 8.1)</p>
  
  <h2>Code:</h2>
  
  <pre><code>import socket
  import struct
  import binascii
  import textwrap
  
  def main():
      # Get host
      host = socket.gethostbyname(socket.gethostname())
      print('IP: {}'.format(host))
  
      # Create a raw socket and bind it
      conn = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
      conn.bind((host, 0))
  
      # Include IP headers
      conn.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
      # Enable promiscuous mode
      conn.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
  
      while True:
          # Recive data
          raw_data, addr = conn.recvfrom(65536)
  
          # Unpack data
          dest_mac, src_mac, eth_proto, data = ethernet_frame(raw_data)
  
          print('\nEthernet Frame:')
          print("Destination MAC: {}".format(dest_mac))
          print("Source MAC: {}".format(src_mac))
          print("Protocol: {}".format(eth_proto))
  
  # Unpack ethernet frame
  def ethernet_frame(data):
      dest_mac, src_mac, proto = struct.unpack('!6s6s2s', data[:14])
      return get_mac_addr(dest_mac), get_mac_addr(src_mac), get_protocol(proto), data[14:]
  
  # Return formatted MAC address AA:BB:CC:DD:EE:FF
  def get_mac_addr(bytes_addr):
      bytes_str = map('{:02x}'.format, bytes_addr)
      mac_address = ':'.join(bytes_str).upper()
      return mac_address
  
  # Return formatted protocol ABCD
  def get_protocol(bytes_proto):
      bytes_str = map('{:02x}'.format, bytes_proto)
      protocol = ''.join(bytes_str).upper()
      return protocol
  
  main()
  </code></pre>
  
  <h2>From this code i get this output:</h2>
  
  <p>IP: 192.168.1.12<br></p>
  
  <p>Ethernet Frame:<br>
  Destination MAC: <strong>45:00:00:43:00:00</strong><br>
  Source MAC: <strong>40:00:2C:11:48:D3</strong><br>
  Protocol: <strong>4266</strong><br></p>
  
  <p>Ethernet Frame:<br>
  Destination MAC: <strong>45:00:00:42:11:E7</strong><br>
  Source MAC: <strong>00:00:80:11:00:00</strong><br>
  Protocol: <strong>C0A8</strong><br></p>
  
  <p>Ethernet Frame:<br>
  Destination MAC: <strong>45:00:00:33:04:D6</strong><br>
  Source MAC: <strong>00:00:80:11:00:00</strong><br>
  Protocol: <strong>C0A8</strong></p>
  
  <p>.<br>.<br>.<br></p>
  
  <p>According to <a href="https://en.wikipedia.org/wiki/EtherType" rel="nofollow noreferrer">EtherType list</a> this protocols don't exist and analysing my traffic with Wireshark i am sure that this MACs don't exist in my LAN</p>
  
  <p>So I'm definitely doing something wrong but I do not understand what<br>
  Thanks in advance</p>