Mail-Address Check: Unterschied zwischen den Versionen

Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Wechseln zu: Navigation, Suche
 
(5 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 *
 
import sys
 
import sys
 
import string
 
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:
 
if len(sys.argv) < 4:
print 'usage: ', sys.argv[0], '  '
+
    usage()
sys.exit(False)
+
  
server = sys.argv[1]
+
i = 1
port = int(sys.argv[2])
+
if len(sys.argv) == 5:
mail_to_check = sys.argv[3]
+
    if sys.argv[i] == '-v':
 +
        verbose = True
 +
        i+=1
 +
    else:
 +
        usage()
  
sSocket = socket(AF_INET, SOCK_STREAM)
+
server = sys.argv[i]
sSocket.connect((server, port))
+
i+=1
recv = sSocket.recv(1024)
+
port = int(sys.argv[i])
#print recv
+
i+=1
 +
mail_to_check = sys.argv[i]
  
sSocket.send('HELO xy\r\n')
 
recv2 = sSocket.recv(1024)
 
#print recv2
 
  
sSocket.send('RSET\r\n')
 
recv1 = sSocket.recv(1024)
 
#print recv1
 
  
sSocket.send('MAIL FROM: addrecheck@example.org\r\n')
+
sSocket = socket(AF_INET, SOCK_STREAM)
recv3 = sSocket.recv(1024)
+
sSocket.connect((server, port))
#print recv3
+
recv = sSocket.recv(1024)
 +
if verbose:
 +
    print (recv.decode())
  
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)
 +
    sSocket.send(c.encode() + '\r\n'.encode())
 +
    recv = sSocket.recv(1024)
 +
    if verbose:
 +
        print (recv.decode())
  
recv5 = recv4.replace("\n", "").replace("\r", "")
+
recv5 = recv.decode().replace("\n", "").replace("\r", "")
 
if recv5[-2:].lower() == 'ok':
 
if recv5[-2:].lower() == 'ok':
sys.exit(True)
+
    if verbose:
 +
        print ('OK')
 +
    sys.exit(True)
 +
if verbose:
 +
    print ('NOK')
 
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)