您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關pcap郵件如何讀取并寫入txt,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
#coding=utf-8
import string
import urllib
import json
from scapy.all import *
import re
readfile =input("請輸入需要分析的文件名:")
mail_port=input("請輸入您要解析的郵件類型(IMAP輸入143,SMTP輸入25,POP3輸入110):")
savefile=input("請輸入您要保存的文件名:")
dpkt1=list()
dpkt2=list()
dpkt = rdpcap(readfile)
print(dpkt)
sessions = dpkt.sessions()
print(sessions)
for session in sessions:
payload = b'' # the payload of one HTTP POST
for packet in sessions[session]:
try:
#if packet['TCP'].dport ==int(mail_port):
dpkt2.append(str(packet[TCP].window)) print(dpkt2) except: pass
string=''.join(dpkt2)
#string=str(dpkt2)
string=string.replace("\r\n","")
string=string.replace("\t","")
string=string.replace("'b'","")
string=string.replace(" ","")
dlist=list()
dNumb=0
i=1
a=len(dpkt2)
print(string)
From = ''.join(re.findall(u"From:(.com>)", string))
To=''.join(re.findall(u"To:(,?.?com?>)",string))
Cc=''.join(re.findall(u"Cc:(,?.?com>)",string))
Bcc=''.join(re.findall(u"Bcc:(,?.?com>)",string))
Subject=''.join(re.findall(u"Subject:([A-Za-z0-9]+)X-Priority",string))
Content = ''.join(re.findall(u"base64([A-Za-z0-9=/+]+?)---", string))
AttachName = ''.join(re.findall(u"filename=(\".?\")", string))
Attach = ''.join(re.findall(u"filename=\".?\"([A-Za-z0-9=/+]+?)---", string))
dict={"From":From,"To":To,"Cc":Cc,"Bcc":Bcc,"Subject":Subject,"Content":base64.b64decode(Content),"AttachName":AttachName,"Attach":Attach}
dlist.append(dict)
dNumb=dNumb+1
f = open(savefile,"w+")
for i in range(dNumb): #原來是dnmb
#f.write(to)
#f.write(str(dlist[i])+"\r\n")
#print(dlist[i])
for key,value in dlist[i].items():
print('{key}:{value}'.format(key = key, value = value))
f.write(str('{key}:{value}'.format(key = key, value = value))+"\r\n")
看完上述內容,你們對pcap郵件如何讀取并寫入txt有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。