summaryrefslogtreecommitdiff
path: root/scripts/profiling/spam.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2015-06-11 11:32:42 -0300
committerKali Kaneko <kali@leap.se>2015-07-27 09:58:29 -0400
commitf5a1f27fb2a2736ce285244a8142960f1caaf501 (patch)
tree53c95287094e86286cd7a41a7aa0f523bd029a52 /scripts/profiling/spam.py
parentbbfb3bb44915004a70702030aa1d2f9336a60938 (diff)
[feat] add smtp port and log level to spam script
Diffstat (limited to 'scripts/profiling/spam.py')
-rwxr-xr-xscripts/profiling/spam.py46
1 files changed, 34 insertions, 12 deletions
diff --git a/scripts/profiling/spam.py b/scripts/profiling/spam.py
index afa26837..3f8d5207 100755
--- a/scripts/profiling/spam.py
+++ b/scripts/profiling/spam.py
@@ -12,15 +12,15 @@ from argparse import ArgumentParser
SMTP_HOST = 'chipmonk.cdev.bitmask.net'
+SMTP_PORT = 465
NUMBER_OF_THREADS = 20
logger = logging.getLogger(__name__)
LOG_FORMAT = '%(asctime)s %(message)s'
-logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
-def _send_email(host, subject, to_addr, from_addr, body_text):
+def _send_email(host, port, subject, to_addr, from_addr, body_text):
"""
Send an email
"""
@@ -31,7 +31,11 @@ def _send_email(host, subject, to_addr, from_addr, body_text):
"",
body_text
), "\r\n")
- server = smtplib.SMTP_SSL(host)
+ logger.debug("setting up smtp...")
+ server = smtplib.SMTP_SSL(host, port)
+ logger.info(
+ "sending message: (%s, %s, %s, %i)"
+ % (from_addr, to_addr, host, port))
server.sendmail(from_addr, [to_addr], body)
server.quit()
@@ -45,20 +49,28 @@ def _parse_args():
'number_of_messages', type=int,
help='The amount of messages email address to spam')
parser.add_argument(
- '-s', dest='server', default=SMTP_HOST,
+ '--server', '-s', default=SMTP_HOST,
help='The SMTP server to use')
parser.add_argument(
- '-t', dest='threads', default=NUMBER_OF_THREADS,
+ '--port', '-p', default=SMTP_PORT,
+ help='The SMTP port to use')
+ parser.add_argument(
+ '--threads', '-t', default=NUMBER_OF_THREADS,
help='The maximum number of parallel threads to launch')
+ parser.add_argument(
+ '--debug', '-d', action='store_true',
+ help='Print debug messages')
return parser.parse_args()
class EmailSenderThread(threading.Thread):
- def __init__(self, host, subject, to_addr, from_addr, body_text,
+ def __init__(self, host, port, subject, to_addr, from_addr, body_text,
finished_fun):
threading.Thread.__init__(self)
+ logger.debug("initilizing thread...")
self._host = host
+ self._port = port
self._subject = subject
self._to_addr = to_addr
self._from_addr = from_addr
@@ -66,16 +78,18 @@ class EmailSenderThread(threading.Thread):
self._finished_fun = finished_fun
def run(self):
+ logger.debug("running thread...")
_send_email(
- self._host, self._subject, self._to_addr, self._from_addr,
- self._body_text)
+ self._host, self._port, self._subject, self._to_addr,
+ self._from_addr, self._body_text)
self._finished_fun()
-def _launch_email_thread(host, subject, to_addr, from_addr, body_text,
+def _launch_email_thread(host, port, subject, to_addr, from_addr, body_text,
finished_fun):
+ logger.debug("will launch email thread...")
thread = EmailSenderThread(
- host, subject, to_addr, from_addr, body_text, finished_fun)
+ host, port, subject, to_addr, from_addr, body_text, finished_fun)
thread.start()
return thread
@@ -89,16 +103,24 @@ class FinishedThreads(object):
def signal(self):
with self._lock:
self._finished = self._finished + 1
- logger.info('Number of messages sent: %d.' % self._finished)
+ logger.info('number of messages sent: %d.' % self._finished)
def _send_messages(args):
host = args.server
+ port = args.port
subject = "Message from Soledad script"
to_addr = args.target_address
from_addr = args.target_address
body_text = "Test message"
+ # configure log level
+ if args.debug:
+ level = logging.DEBUG
+ else:
+ level = logging.INFO
+ logging.basicConfig(format=LOG_FORMAT, level=level)
+
semaphore = threading.Semaphore(args.threads)
threads = []
finished_threads = FinishedThreads()
@@ -111,7 +133,7 @@ def _send_messages(args):
semaphore.acquire()
threads.append(
_launch_email_thread(
- host, subject, to_addr, from_addr, body_text,
+ host, port, subject, to_addr, from_addr, body_text,
_finished_fun))
for t in threads: