Skip to content

Commit

Permalink
pop3
Browse files Browse the repository at this point in the history
  • Loading branch information
collinsctk committed May 14, 2016
1 parent 42b3ff8 commit fefe600
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 61 deletions.
Binary file modified Network/DHCP/__pycache__/DHCP_Discover.cpython-34.pyc
Binary file not shown.
Binary file modified Network/DHCP/__pycache__/DHCP_Request.cpython-34.pyc
Binary file not shown.
46 changes: 29 additions & 17 deletions Network/POP3/POP3_REC_Attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,47 @@ def qyt_rec_mail(mailserver, mailuser, mailpasswd):

for i in range(msgCount):#逐个读取邮件
hdr, message, octets = server.retr(i + 1)#读取邮件
str_message = email.message_from_bytes(b'\n'.join(message))

for part in str_message.walk():
#print(part.get_content_type())
str_message = email.message_from_bytes(b'\n'.join(message))#把所有信息加在一起
for part in str_message.walk():#遍历所有内容
if part.get_content_maintype() == 'multipart':
part_dict = part.items()
for key in part_dict:
if key[0] == 'Subject':
if re.match('=\?(.*)\?\w\?(.*)=\?',key[1]).groups():
part_dict = part.items()#提取'multipart'内容产生字典
for key in part_dict:#遍历字典
if key[0] == 'Subject':#如果为主题
try:#尝试解码
re_result = re.match('=\?(.*)\?\w\?(.*)\?=',key[1]).groups()
prefix = '=?' + re_result[0]
suffix = '?='
middle = re_result[1]
decoded = base64.b64decode(middle)
mail_prefix = str(decoded.decode(re_result[0]))
else:
except Exception:#如果解码失败,就使用原文
mail_prefix = key[1]
continue
filename = part.get_filename()
if filename == None:
filename = part.get_filename()#提取文件名
if filename == None:#如果没有文件名
mail_file_name = mail_prefix + '_' + str(i) + '.txt'
fp = open(mail_file_name, 'wb')
#使用主题的名字产生文件名
for key in part_dict:
string = key[0] + '===>' + key[1] + '\n'
fp.write(string.encode())
if key[0] == 'Subject':#如果是主题需要解码
try:
re_result = re.match('=\?(.*)\?\w\?(.*)\?=',key[1]).groups()
middle = re_result[1]
decoded = base64.b64decode(middle)
Subject = str(decoded.decode(re_result[0]))
except Exception:
Subject = key[1]
fp = open(mail_file_name, 'a')
string = key[0] + '===>' + Subject + '\n'
fp.write(string)
fp.close
else:#不是主题正常写入
fp = open(mail_file_name, 'a')
string = key[0] + '===>' + key[1] + '\n'
fp.write(string)
fp.close
fp = open(mail_file_name, 'ab')
fp.write(b'Main Body ===>')
fp.write(part.get_payload(decode=1))
fp.close
else:
else:#提取附件,并且写入成为文件!
filename = filename.encode("utf-8").decode()
mail_file_name = mail_prefix + '_' + str(i) + '+' + filename
fp = open(mail_file_name, 'wb')
Expand Down
Binary file added Network/POP3/qytang主题测试_1+测试.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Network/POP3/qytang主题测试_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Received===>from [192.168.214.200] (unknown [106.3.42.51])
by smtp2 (Coremail) with SMTP id DNGowAB3fr57fjZXElopAQ--.21915S2;
Sat, 14 May 2016 09:25:15 +0800 (CST)
Content-Type===>multipart/mixed; boundary="===============5362202242919354841=="
MIME-Version===>1.0
Subject===>qytang主题测试
From===>collinsctk@163.com
To===>collinsctk@qytang.com;collinsctk@163.com
Date===>Sat, 14 May 2016 01:25:15 -0000
X-CM-TRANSID===>DNGowAB3fr57fjZXElopAQ--.21915S2
Message-Id===><57367E7C.517BEF.01213@m50-132.163.com>
X-Coremail-Antispam===>1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73
VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4RNqXdDUUUU
X-Originating-IP===>[106.3.42.51]
X-CM-SenderInfo===>xfrozxxqvf3yi6rwjhhfrp/1tbiORxpgFXlTaV2TQAAsv
X-EsetId===>37303A29E20FD06F617361
Main Body ===>qytang正文测试
Binary file added Network/POP3/亁颐堂主题测试_0+测试.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Network/POP3/亁颐堂主题测试_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Received===>from [192.168.214.200] (unknown [106.3.42.51])
by smtp3 (Coremail) with SMTP id DdGowADHZ4xofjZXQP2TAA--.16133S2;
Sat, 14 May 2016 09:24:57 +0800 (CST)
Content-Type===>multipart/mixed; boundary="===============5340261990132682623=="
MIME-Version===>1.0
Subject===>亁颐堂主题测试
From===>collinsctk@163.com
To===>collinsctk@qytang.com;collinsctk@163.com
Date===>Sat, 14 May 2016 01:24:56 -0000
X-CM-TRANSID===>DdGowADHZ4xofjZXQP2TAA--.16133S2
Message-Id===><57367E69.516016.01214@m50-133.163.com>
X-Coremail-Antispam===>1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73
VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4R9o7MUUUUU
X-Originating-IP===>[106.3.42.51]
X-CM-SenderInfo===>xfrozxxqvf3yi6rwjhhfrp/1tbiJglpgFXlS914VwAAsP
X-EsetId===>37303A29E20FD06F617361
Main Body ===>亁颐堂正文测试
40 changes: 0 additions & 40 deletions Network/POP3/测试1_0.txt

This file was deleted.

4 changes: 2 additions & 2 deletions Network/SMTP/SMTP_SEND_MAIL_Attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def qyt_smtp_attachment(mailserver, username, password, From, To, Subj, Main_Bod
msg["Date"] = Date

part = MIMEText(Main_Body)
msg.attach(part)
msg.attach(part)#把‘MIMEMultipart’添加到邮件

if files:
for file in files:
part = MIMEApplication(open(file,'rb').read())
part.add_header('Content-Disposition', 'attachment', filename=file)
msg.attach(part)
msg.attach(part) #读取附件,添加到邮件

server = smtplib.SMTP(mailserver)#连接邮件服务器
server.login(username, password)#通过用户名和密码登录邮件服务器
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Network/TFTP/tftpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def qyt_ftpclient(server, filedir, file, operation=1):
print()

if __name__ == '__main__':
qyt_ftpclient('202.100.1.138', '.', 'snmpv2r1-confg', operation=1)
#qyt_ftpclient('202.100.1.138', '.', 'test-confg', operation=2)
#qyt_ftpclient('202.100.1.138', '.', 'snmpv2r1-confg', operation=1)
qyt_ftpclient('202.100.1.138', '.', 'test-confg', operation=2)
127 changes: 127 additions & 0 deletions Network/TFTP/tftpdir/test-confg
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname SNMPv2R1
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
!
!
ip cef
no ip domain lookup
!
!
ip auth-proxy max-nodata-conns 3
ip admission max-nodata-conns 3
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
archive
log config
hidekeys
!
!
!
!
ip tcp synwait-time 5
!
!
!
!
interface FastEthernet0/0
ip address 202.100.23.3 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
duplex auto
speed auto
!
interface FastEthernet1/0
ip address 202.100.1.3 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet2/0
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet3/0
no ip address
shutdown
duplex auto
speed auto
!
router ospf 1
log-adjacency-changes
!
no ip http server
no ip http secure-server
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 202.100.23.2
!
!
!
snmp-server community public RO
snmp-server community private RW
snmp-server enable traps snmp linkdown linkup
snmp-server enable traps config
snmp-server host 202.100.1.138 version 2c R1
!
!
!
!
control-plane
!
!
!
!
!
!
!
!
alias exec c configure terminal
alias exec i show ip inter brie
alias exec e show crypto engine connections active
alias exec s sh run
!
line con 0
exec-timeout 0 0
logging synchronous
line aux 0
exec-timeout 0 0
logging synchronous
line vty 0 4
password cisco
login
line vty 5 15
password cisco
login
!
!
end
Binary file modified Network/Tools/__pycache__/Change_Chaddr_To_MAC.cpython-34.pyc
Binary file not shown.
Binary file modified Network/Tools/__pycache__/Change_MAC_To_Bytes.cpython-34.pyc
Binary file not shown.
Binary file modified Network/Tools/__pycache__/GET_MAC.cpython-34.pyc
Binary file not shown.
Binary file modified Network/Tools/__pycache__/Random_MAC.cpython-34.pyc
Binary file not shown.

0 comments on commit fefe600

Please sign in to comment.