Search code examples
pythonscapypyshark

How Do I get Packets from Locally hosted website on remote computer with pyshark


I am trying to get packets from a website hosted locally on remote computer(Test purpose) using pyshark.

Here is my code:

import pyshark

def print_live_dns():
   capture = pyshark.LiveCapture("wlan0")
   for packet in capture:
      # print(packet)
      with open('packets.txt', 'a') as f:
         f.write(str(packet))
      if "DNS" in packet and not packet.dns.flags_response.int_value:
         print(packet.dns.qry_name)

if __name__ == "__main__":
    print_live_dns()

With this code I only get packets from the internet. which is not what I need. How do I achieve this? using either pyshark, scapy, nmap etc


Solution

  • You can use set intersection

    >>> from functools import reduce
    >>>
    >>> my_list = [[2,3,5,6,7,8,9], [2,4,78,23,13,7], [3,2,5,98,23,1,34]]
    >>> list(reduce(lambda x, y: set(x).intersection(set(y)), my_list))
    [2]
    >>>