Scapy和python收到的部分数据包

时间:2018-11-13 14:22:04

标签: python html python-3.x http scapy

我正在尝试嗅探长数据包,特别是包含html代码的http数据包。
这是我正在使用的代码:

from scapy.all import *

f = open('outHTML.txt','wb')

def packet_callback(pkt):
    if pkt.haslayer(Raw) and pkt[Raw].load:
        if str(pkt[Raw].load).find("<html") != -1:
            f.write(bytes('\n' + "=" * 50 + '\n', encoding = "utf8"))
            f.write(pkt[Raw].load)
            f.flush()

sniff(prn=packet_callback)

由于某种原因,我嗅探时没有得到所有的代码。 例如,我得到了以下结果:

HTTP/1.1 200 OK
Date: Tue, 13 Nov 2018 14:00:57 GMT
Expires: Wed, 17 Aug 2005 00:00:00 GMT
Last-Modified: Tue, 13 Nov 2018 14:00:57 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Contenet-Type-Options: nosniff
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Set-Cookie: TS01b8cd54=019790ad781b859b67afd842e20f0cefeebdf19683a53ff0c282ad209e1bcd0e8d590944badeef97f3d54ed8ab8c7efc5614812de7b7daaddfa8ce09ddf390077f7d2652ce; Path=/; Domain=.rishuy.mot.gov.il
Transfer-Encoding: chunked

4000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="he-il" lang="he-il" dir="rtl">
<head>


<meta http-equiv="X-UA-Compatible" content="IE=edge">


<meta name="viewport" content="width=device-width, initial-scale=1.0" />


<base href="http://rishuy.mot.gov.il/he/" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="רשיומט, רישוי קול, משרד הרישוי, רישוי נהיגה, רישוי כלי רכב" />
    <meta name="description" content="משרד התחבורה - רשות הרישוי" />
    <title>רשות הרישוי</title>
    <link href="/he/?format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
    <link href="/he/?format=feed&amp;type=atom" rel="alternate" t

后跟很多 NUL字节。
(网站上有html代码而不是这些NUL字节)。
我如何获得其余代码?

0 个答案:

没有答案