Hi Guys. I need some help with the coding for my program.
This coding is suppose to sort text file according to the latest date and send
the latest file. Attach it to my email and sent to another email account. But
somehow the program is unable to send email.
[CODE]#!/usr/bin/python
import os, glob, smtplib, datetime
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
process_list=[]
AP_filelist=[]
Client_filelist=[]
BlackClient_filelist=[]
sniff_assoc = 0
i = 0
to = "iamsiaozhar...@hotmail.sg"
gmail_user = "root.phidg...@gmail.com"
gmail_pwd = "rootphidget"
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(text))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()
Client_files = glob.glob('/root/wifi/Output_assoc/*Rouge-Client*.txt')
def get_oldest_Client_file(Client_files):
for data in Client_files:
stats = os.stat(data)
Client_filelist.append(data)
sortedClient = sorted(Client_filelist)
return sortedClient[0]
BlackClient_files = glob.glob('/root/wifi/Output_arp/*DeAuth-Client*.txt')
def get_oldest_BlackClient_file(BlackClient_files):
for data in BlackClient_files:
stats = os.stat(data)
BlackClient_filelist.append(data)
sortedBlackClient = sorted(BlackClient_filelist)
return sortedBlackClient[0]
if __name__=='__main__':
try:
if os.path.getsize(get_oldest_Client_file(Client_files)) > 1:
mail("root.phidg...@gmail.com",
"Rouge Client Found",
"Client MAC address in the attachment",
get_oldest_Client_file(Client_files))
print str(datetime.datetime.now()) + ' -- ' +
get_oldest_Client_file(Client_files) + ' was sent.'
os.remove(get_oldest_Client_file(Client_files))
else:
for line in os.popen("ps -e"):
fields = line.split()
process = fields[3]
process_list.append(process)
for pro in process_list:
if pro == 'sniff_assoc':
sniff_assoc = 1
i+=1
if sniff_assoc == 0:
os.remove(get_oldest_Client_file(Client_files))
print str(datetime.datetime.now()) + ' -- ' + 'program is not
running. ' + get_oldest_Client_file(Client_files) + ' is remove.'
else:
print str(datetime.datetime.now()) + ' -- ' + 'Client file is
still writing.'
except:
print str(datetime.datetime.now()) + ' -- ' + 'No AP file to send.'
try:
if os.path.getsize(get_oldest_BlackClient_file(BlackClient_files)) > 1:
mail("root.phidg...@gmail.com",
"DeAuth Rouge Client",
"Client MAC address in the attachment.",
get_oldest_BlackClient_file(BlackClient_files))
print str(datetime.datetime.now()) + ' -- ' +
get_oldest_BlackClient_file(BlackClient_files) + ' was sent.'
os.remove(get_oldest_BlackClient_file(BlackClient_files))
else:
for line in os.popen("ps -e"):
fields = line.split()
process = fields[3]
process_list.append(process)
for pro in process_list:
if pro == 'sniff_arp':
sniff_assoc = 1
i+=1
if sniff_assoc == 0:
os.remove(get_oldest_BlackClient_file(BlackClient_files))
print str(datetime.datetime.now()) + ' -- ' + 'program is not
running. ' + get_oldest_BlackClient_file(BlackClient_files) + ' is REMOVED!!'
else:
print str(datetime.datetime.now()) + ' -- ' + 'DeAuth client
file is still writing!'
except:
print str(datetime.datetime.now()) + ' -- ' + 'No DeAuth client file
to send.'[/CODE]
--
http://mail.python.org/mailman/listinfo/python-list