How to sniff HTTP packets in python?

后端 未结 4 816
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 15:26

I want to sniff all the HTTP packets in my computer via python(version2.6.. is this possible? can I do it with scapy, or without other external modules?

4条回答
  •  既然无缘
    2020-12-05 15:39

    FTR, Scapy will support HTTP packets starting from 2.4.3: https://scapy.readthedocs.io/en/latest/layers/http.html

    >>> HTTPRequest().show()
    ###[ HTTP Request ]###
      Method= 'GET'
      Path= '/'
      Http_Version= 'HTTP/1.1'
      A_IM= None
      Accept= None
      Accept_Charset= None
      Accept_Datetime= None
      Accept_Encoding= None
      [...]
    

    Sniff demo:

    from scapy.layers.http import * # read the doc
    from scapy.sendrecv import sniff
    sniff(lfilter=lambda x: HTTP in x, prn=lambda x: x.summary())
    

提交回复
热议问题