Last active
May 31, 2016 21:15
-
-
Save cyberplant/79020c451cda678bb46f31ba126ff6bf to your computer and use it in GitHub Desktop.
Simple code to test SMTP auth on servers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import socket | |
import argparse | |
import time | |
def read(s): | |
print s.recv(512), | |
def send(s, text): | |
print text | |
s.send(text) | |
s.send("\r\n") | |
read(s) | |
parser = argparse.ArgumentParser(description='Test SMTP auth.') | |
parser.add_argument('username', help='Username') | |
parser.add_argument('password', help='Password') | |
parser.add_argument('server', help='Server') | |
parser.add_argument('port', default=25, help='port') | |
parser.add_argument('--ssl', action="store_true", help='SSL') | |
args = parser.parse_args() | |
b64user = base64.b64encode(args.username) | |
b64pass = base64.b64encode(args.password) | |
s = socket.socket() | |
s.connect((args.server, int(args.port))) | |
read(s) | |
time.sleep(1) | |
send(s, "EHLO smtptest.com") | |
if args.ssl: | |
send(s, "STARTTLS") | |
import ssl | |
s = ssl.wrap_socket(s) | |
send(s, "AUTH LOGIN") | |
send(s, b64user) | |
send(s, b64pass) | |
send(s, "QUIT") | |
if s: | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment