Mail-Address Check: Unterschied zwischen den Versionen

Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Wechseln zu: Navigation, Suche
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 5: Zeile 5:
 
# pss.ZweierNet.ch
 
# pss.ZweierNet.ch
 
#
 
#
# All Rights reserved.
+
# This is absolutely free software.
# This program is free software; you can redistribute it and/or
+
# Use it as you like but don't point the finger of blame to me.
# 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 *
 
from socket import *
Zeile 23: Zeile 17:
 
mail_to_check = "";
 
mail_to_check = "";
  
commands = [ 'HELO xy',
+
commands = ['HELO xy',
    'RSET',
+
            'RSET',
    'MAIL FROM: mailverification@zweiernet.ch',
+
            'MAIL FROM: mailverification@example.org',
    'RCPT TO: <__mail_to_check__>']
+
            'RCPT TO: <__mail_to_check__>']
  
  
 
#-- subs
 
#-- subs
 
def usage ():
 
def usage ():
print('usage: ', sys.argv[0], '[-v] < mailserver-to-check-for > < port-on-server-25-or-587 > < email-adress-to-check >')
+
    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)
  
 
#-- end subs
 
#-- end subs
Zeile 38: Zeile 32:
  
 
if len(sys.argv) < 4:
 
if len(sys.argv) < 4:
usage()
+
    usage()
  
 
i = 1
 
i = 1
 
if len(sys.argv) == 5:
 
if len(sys.argv) == 5:
if sys.argv[i] == '-v':
+
    if sys.argv[i] == '-v':
verbose = True
+
        verbose = True
i+=1
+
        i+=1
else:
+
    else:
usage()
+
        usage()
  
 
server = sys.argv[i]
 
server = sys.argv[i]
Zeile 60: Zeile 54:
 
recv = sSocket.recv(1024)
 
recv = sSocket.recv(1024)
 
if verbose:
 
if verbose:
print (recv.decode())
+
    print (recv.decode())
sys.stdout.flush()
+
  
 
for c in commands:
 
for c in commands:
c = c.replace('__mail_to_check__', str(mail_to_check))
+
    c = c.replace('__mail_to_check__', str(mail_to_check))
if verbose:
+
    if verbose:
print(c)
+
        print(c)
sys.stdout.flush()
+
    sSocket.send(c.encode() + '\r\n'.encode())
sSocket.send(c.encode() + '\r\n'.encode())
+
    recv = sSocket.recv(1024)
recv = sSocket.recv(1024)
+
    if verbose:
if verbose:
+
        print (recv.decode())
print (recv.decode())
+
sys.stdout.flush()
+
  
 
recv5 = recv.decode().replace("\n", "").replace("\r", "")
 
recv5 = recv.decode().replace("\n", "").replace("\r", "")
 
if recv5[-2:].lower() == 'ok':
 
if recv5[-2:].lower() == 'ok':
if verbose:
+
    if verbose:
print ('OK')
+
        print ('OK')
sys.stdout.flush()
+
    sys.exit(True)
sys.exit(True)
+
 
if verbose:
 
if verbose:
print ('NOK')
+
    print ('NOK')
sys.stdout.flush()
+
 
sys.exit(False)
 
sys.exit(False)

Aktuelle Version vom 26. Dezember 2015, 03:06 Uhr

#!/usr/bin/python
 
# Copyright (c) 2015 by Peter_Siegrist(SystemLoesungen)  (PSS @ ZweierNet.ch)
# pss.ZweierNet.ch
#
# This is absolutely free software. 
# Use it as you like but don't point the finger of blame to me.
#
 
 
from socket import *
import sys
import string
 
verbose = False
mail_to_check = "";
 
commands = ['HELO xy',
            'RSET',
            'MAIL FROM: mailverification@example.org',
            '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())
 
for c in commands:
    c = c.replace('__mail_to_check__', str(mail_to_check))
    if verbose:
        print(c)
    sSocket.send(c.encode() + '\r\n'.encode())
    recv = sSocket.recv(1024)
    if verbose:
        print (recv.decode())
 
recv5 = recv.decode().replace("\n", "").replace("\r", "")
if recv5[-2:].lower() == 'ok':
    if verbose:
        print ('OK')
    sys.exit(True)
if verbose:
    print ('NOK')
sys.exit(False)