Mail-Address Check: Unterschied zwischen den Versionen

Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Wechseln zu: Navigation, Suche
Zeile 20: Zeile 20:
 
import string
 
import string
  
if len(sys.argv) < 4:
+
verbose = False
print 'usage: ', sys.argv[0], ' < mailserver-to-check-for > < port-on-server-25-or-587 > < email-adress-to-check >'
+
mail_to_check = "";
 +
 
 +
commands = ['HELO xy',
 +
'RSET',
 +
'MAIL FROM: mailverification@zweiernet.ch',
 +
'RCPT TO: <__mail_to_check__>']
 +
 
 +
 
 +
#-- subs
 +
def usage ():
 +
print('usage: ', sys.argv[0], '[-v] < mailserver-to-check-for > < port-on-server-25-or-587 > < email-adress-to-check >')
 
sys.exit(False)
 
sys.exit(False)
  
server = sys.argv[1]
+
#-- end subs
port = int(sys.argv[2])
+
mail_to_check = sys.argv[3]
+
  
sSocket = socket(AF_INET, SOCK_STREAM)
 
sSocket.connect((server, port))
 
recv = sSocket.recv(1024)
 
#print recv
 
  
sSocket.send('HELO xy\r\n')
+
if len(sys.argv) < 4:
recv2 = sSocket.recv(1024)
+
usage()
#print recv2
+
  
sSocket.send('RSET\r\n')
+
i = 1
recv1 = sSocket.recv(1024)
+
if len(sys.argv) == 5:
#print recv1
+
if sys.argv[i] == '-v':
 +
verbose = True
 +
i+=1
 +
else:
 +
usage()
  
sSocket.send('MAIL FROM: addrecheck@example.org\r\n')
+
server = sys.argv[i]
recv3 = sSocket.recv(1024)
+
i+=1
#print recv3
+
port = int(sys.argv[i])
 +
i+=1
 +
mail_to_check = sys.argv[i]
 +
 
 +
 
 +
 
 +
sSocket = socket(AF_INET, SOCK_STREAM)
 +
sSocket.connect((server, port))
 +
recv = sSocket.recv(1024)
 +
if verbose:
 +
print (recv.decode())
 +
sys.stdout.flush()
  
sSocket.send('RCPT TO: ' + mail_to_check + '\r\n')
+
for c in commands:
recv4 = sSocket.recv(1024)
+
c = c.replace('__mail_to_check__', str(mail_to_check))
#print recv4
+
if verbose:
 +
print(c)
 +
sys.stdout.flush()
 +
sSocket.send(c.encode() + '\r\n'.encode())
 +
recv = sSocket.recv(1024)
 +
if verbose:
 +
print (recv.decode())
 +
sys.stdout.flush()
  
recv5 = recv4.replace("\n", "").replace("\r", "")
+
recv5 = recv.decode().replace("\n", "").replace("\r", "")
 
if recv5[-2:].lower() == 'ok':
 
if recv5[-2:].lower() == 'ok':
 +
if verbose:
 +
print ('OK')
 +
sys.stdout.flush()
 
sys.exit(True)
 
sys.exit(True)
 +
if verbose:
 +
print ('NOK')
 +
sys.stdout.flush()
 
sys.exit(False)
 
sys.exit(False)

Version vom 24. Dezember 2015, 14:41 Uhr

#!/usr/bin/python
 
# Copyright (c) 2015 by Peter_Siegrist(SystemLoesungen)  (PSS @ ZweierNet.ch)
# pss.ZweierNet.ch
#
# All Rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
 
from socket import *
import sys
import string
 
verbose = False
mail_to_check = "";
 
commands = ['HELO xy',
			'RSET',
			'MAIL FROM: mailverification@zweiernet.ch',
			'RCPT TO: <__mail_to_check__>']
 
 
#-- subs
def usage ():
	print('usage: ', sys.argv[0], '[-v] < mailserver-to-check-for > < port-on-server-25-or-587 > < email-adress-to-check >')
	sys.exit(False)
 
#-- end subs
 
 
if len(sys.argv) < 4:
	usage()
 
i = 1
if len(sys.argv) == 5:
	if sys.argv[i] == '-v':
		verbose = True
		i+=1
	else:
		usage()
 
server = sys.argv[i]
i+=1
port = int(sys.argv[i])
i+=1
mail_to_check = sys.argv[i]
 
 
 
sSocket = socket(AF_INET, SOCK_STREAM)
sSocket.connect((server, port))
recv = sSocket.recv(1024)
if verbose:
	print (recv.decode())
	sys.stdout.flush()
 
for c in commands:
	c = c.replace('__mail_to_check__', str(mail_to_check))
	if verbose:
		print(c)
		sys.stdout.flush()
	sSocket.send(c.encode() + '\r\n'.encode())
	recv = sSocket.recv(1024)
	if verbose:
		print (recv.decode())
		sys.stdout.flush()
 
recv5 = recv.decode().replace("\n", "").replace("\r", "")
if recv5[-2:].lower() == 'ok':
	if verbose:
		print ('OK')
		sys.stdout.flush()
	sys.exit(True)
if verbose:
	print ('NOK')
	sys.stdout.flush()
sys.exit(False)