[Tutor] Looking for peer review

Joel Ricker joel@prettyhipprogramming.com
Thu, 11 Jul 2002 12:48:53 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_001E_01C228D9.50324040
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Below is a program that I've been working on that reports changes in =
ipaddresses.  I work in a retail store and we have two other stores =
about an hour drive away.  Once a week the owner comes down and makes =
backups of our inventory and gives us copies of inventories from the =
other two stores.  The owner decided to set us all up with a broadband =
connection and use PCAnywhere to connect and make changes to the system.

Of course the problem is that the ip addresses of all the connections =
will change at least once a day.  When he complained about having to =
call us for the ip address whenever he wanted to login, I knew Python =
would do the trick :)

The purpose of this program is to check the ip address periodically and =
if it changes, connect to an smtp server and send an e-mail reporting =
the change.  That way, he should always have the current ip address of =
our system.

I'd like for everyone to critique my program and give me any pointers on =
making it better and helping me become a better python programmer.  This =
is my first "real" python program -- something that's not throw away =
code and that will be used by someone else.=20

## ipwatch.py
import socket, getopt, sys, time, smtplib

def usage(evalue):
    ''' Show instructions and pass exit evalue '''
   =20
    print
    print "ipwatch by Joel Ricker (joel@prettyhipprogramming.com)"
    print "Monitors current machines IP address and reports any changes =
by e-mail."
    print   =20
    print "Usage:python ipwatch.py --help | --to <to address> --from =
<from address> "
    print "[--smtp <smtp address>] [--port <port>] [--user <username>] =
[--pass <password>] [--wait <minutes>]"   =20
    print
    print "Options:"
    print "\t--help\tShows this help message."
    print "\t--to\tE-mail address to send reports to."
    print "\t--from\tE-mail address to set as reply to."
    print "\t--smtp\tAddress of smtp server to send mail through."
    print "\t\tDefaults to localhost."
    print "\t--port\tPort address of smtp server. Defaults to 25"
    print "\t--user\tIf smtp server requires authorization, the username =
to login as."
    print "\t--pass\tIf smtp server requires authorization, the password =
to login as."
    print "\t--wait\tTime in minutes to wait between ip address checks."
   =20
    sys.exit(evalue)   =20
   =20

def get_addy():
    try:
        addy =3D socket.gethostbyname(socket.getfqdn())
    except:
        sys.stderr.write("Socket Error: Couldn't aquire address of this =
machine.")
        sys.exit(2)
    else:
        return addy
       =20
def main():     =20

    # Load the file that holds the current ip address of this machine    =

    try:
        f =3D file("ipwatch.dat", "r")
        addy =3D f.readline()
        f.close()
    except:
        f =3D file("ipwatch.dat", "w")
        addy =3D get_addy()       =20
        f.write(addy)
        f.close()       =20
   =20
    # Load command line options
    try:
        opts, args =3D getopt.getopt(sys.argv[1:], "hs:p:t:f:u:p:w:",
                                     ["help", "smtp=3D", "port=3D", =
"to=3D", "from=3D", "user=3D", "pass=3D", "wait=3D"])
    except getopt.GetoptError:
        # print help information and exit:
        usage(2)       =20
    else:
        if not len(opts):
            usage(2)           =20

    smtpaddy =3D 'localhost'
    port =3D 25
    fromwho =3D None
    towho =3D None
    user =3D None
    password =3D None
    wait =3D None

    print opts
    print args
    # Process options
    for o, a in opts:
       =20
        # Help - prints out the instructions for use
        if o in ("-h", "--help"):
            usage(0)           =20
           =20
        # SMTP - the address of the smtp server to send the e-mail =
through
        if o in ("-s", "--smtp"):
            smtpaddy =3D a

        # Port - port
        if o in ("-p", "--port"):
            port =3D a

        # To - the address to send the e-mail to
        if o in ("-t", "--to"):
            towho =3D a

        # From - the reply address
        if o in ("-f", "--from"):
            fromwho =3D a
           =20
        # Username - the username to login as if required
        if o in ("-u", "--user"):
            user =3D a
           =20
        # Password - the password of the smtp server if required
        if o in ("-p", "--pass"):
            password =3D a

        # Time - amount of time in minutes to wait
        if o in ("-w", "--wait"):           =20
            wait =3D int(a) * 60     =20

    # Check for required and valid command-line options
    if towho is None:
        sys.stderr.write("To address required.")
        usage(2)       =20
    if fromwho is None:
        sys.stderr.write("From address required.")
        usage(2)   =20
    if wait < 300:
        sys.stderr.write("Invalid wait value.")
        usage(2)
       =20
       =20
   =20
    # Now we loop, checking the current address of the machine against =
the address stored
    # in the file.  If we have a new address, we store that address in =
the file and report
    # the new address by e-mail.  We're depending on Window's shutdown =
signal to stop
    # properly
    while (1):
        newaddy =3D get_addy()
        if addy !=3D newaddy:
            print "New addy: ", newaddy
            f =3D open("ipwatch.dat", "w")
            f.write(newaddy)
            f.close()
              =20
            try:
                s =3D smtplib.connect(smtpaddy, port)
                if user is not None:                   =20
                    try:
                        s.login(user, password)
                    except SMTPAuthenticationError:
                        sys.stderr.write("Error logging into SMTP =
server.  Check username and password and re-attempt")
                s.sendmail(towho, fromwho, newaddy)
                s.quit()
               =20

            except SMTPException, reason:
                sys.stderr.write("SMTP Error: %s", (reason))
            addy =3D newaddy
        print "The current address is", addy
        time.sleep(wait)  =20
       =20
   =20

if __name__ =3D=3D "__main__":
    main()
   =20
Thanks
Joel

------=_NextPart_000_001E_01C228D9.50324040
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2479.6" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Below is a program that I've been =
working on that=20
reports changes in ipaddresses.&nbsp; I work in a retail store and we =
have two=20
other stores about an hour drive away.&nbsp; Once a week the owner comes =
down=20
and makes backups of our inventory and gives us copies of inventories =
from the=20
other two stores.&nbsp; The owner decided to set us all up with a =
broadband=20
connection and use PCAnywhere to connect and make changes to the=20
system.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Of course the problem is that the ip =
addresses of=20
all the connections will change at least once a day.&nbsp; When he =
complained=20
about having to call us for the ip address whenever he wanted to login, =
I knew=20
Python would do the trick :)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The purpose of this program is to check =
the ip=20
address periodically and if it changes, connect to an smtp server and =
send an=20
e-mail reporting the change.&nbsp; That way, he should always have the =
current=20
ip address of our system.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'd like for everyone to critique my =
program and=20
give me any pointers on making it better and helping me become a better =
python=20
programmer.&nbsp; This is my first "real" python program -- something =
that's not=20
throw away code and that will be used by someone =
else.&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>## ipwatch.py</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>import socket, getopt, sys, time,=20
smtplib</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def =
usage(evalue):<BR>&nbsp;&nbsp;&nbsp; ''' Show=20
instructions and pass exit evalue '''<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; print<BR>&nbsp;&nbsp;&nbsp; print "ipwatch by =
Joel Ricker=20
(<A=20
href=3D"mailto:joel@prettyhipprogramming.com">joel@prettyhipprogramming.c=
om</A>)"<BR>&nbsp;&nbsp;&nbsp;=20
print "Monitors current machines IP address and reports any changes by=20
e-mail."<BR>&nbsp;&nbsp;&nbsp; print&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
print "Usage:python ipwatch.py --help | --to &lt;to address&gt; --from =
&lt;from=20
address&gt; "<BR>&nbsp;&nbsp;&nbsp; print "[--smtp &lt;smtp address&gt;] =
[--port=20
&lt;port&gt;] [--user &lt;username&gt;] [--pass &lt;password&gt;] =
[--wait=20
&lt;minutes&gt;]"&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
print<BR>&nbsp;&nbsp;&nbsp; print "Options:"<BR>&nbsp;&nbsp;&nbsp; print =

"\t--help\tShows this help message."<BR>&nbsp;&nbsp;&nbsp; print =
"\t--to\tE-mail=20
address to send reports to."<BR>&nbsp;&nbsp;&nbsp; print =
"\t--from\tE-mail=20
address to set as reply to."<BR>&nbsp;&nbsp;&nbsp; print =
"\t--smtp\tAddress of=20
smtp server to send mail through."<BR>&nbsp;&nbsp;&nbsp; print =
"\t\tDefaults to=20
localhost."<BR>&nbsp;&nbsp;&nbsp; print "\t--port\tPort address of smtp =
server.=20
Defaults to 25"<BR>&nbsp;&nbsp;&nbsp; print "\t--user\tIf smtp server =
requires=20
authorization, the username to login as."<BR>&nbsp;&nbsp;&nbsp; print=20
"\t--pass\tIf smtp server requires authorization, the password to login=20
as."<BR>&nbsp;&nbsp;&nbsp; print "\t--wait\tTime in minutes to wait =
between ip=20
address checks."<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
sys.exit(evalue)&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; =
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def get_addy():<BR>&nbsp;&nbsp;&nbsp;=20
try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addy =3D=20
socket.gethostbyname(socket.getfqdn())<BR>&nbsp;&nbsp;&nbsp;=20
except:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
sys.stderr.write("Socket=20
Error: Couldn't aquire address of this=20
machine.")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
sys.exit(2)<BR>&nbsp;&nbsp;&nbsp;=20
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
addy<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>def=20
main():&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; # Load the file that =
holds the=20
current ip address of this machine&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f =3D =
file("ipwatch.dat",=20
"r")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addy =3D=20
f.readline()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
f.close()<BR>&nbsp;&nbsp;&nbsp;=20
except:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f =3D =
file("ipwatch.dat",=20
"w")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addy =3D=20
get_addy()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
f.write(addy)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
f.close()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; # Load command line options<BR>&nbsp;&nbsp;&nbsp; =

try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opts, args =3D=20
getopt.getopt(sys.argv[1:],=20
"hs:p:t:f:u:p:w:",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;=20
["help", "smtp=3D", "port=3D", "to=3D", "from=3D", "user=3D", "pass=3D", =

"wait=3D"])<BR>&nbsp;&nbsp;&nbsp; except=20
getopt.GetoptError:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # =
print help=20
information and exit:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
usage(2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not=20
len(opts):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
usage(2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; smtpaddy =3D=20
'localhost'<BR>&nbsp;&nbsp;&nbsp; port =3D 25<BR>&nbsp;&nbsp;&nbsp; =
fromwho =3D=20
None<BR>&nbsp;&nbsp;&nbsp; towho =3D None<BR>&nbsp;&nbsp;&nbsp; user =3D =

None<BR>&nbsp;&nbsp;&nbsp; password =3D None<BR>&nbsp;&nbsp;&nbsp; wait =
=3D=20
None</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; print =
opts<BR>&nbsp;&nbsp;&nbsp;=20
print args<BR>&nbsp;&nbsp;&nbsp; # Process options<BR>&nbsp;&nbsp;&nbsp; =
for o,=20
a in opts:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Help - prints out the=20
instructions for use<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if o =
in=20
("-h",=20
"--help"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
usage(0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # SMTP - the address of =
the smtp=20
server to send the e-mail =
through<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
if o in ("-s",=20
"--smtp"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
smtpaddy =3D a</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Port -=20
port<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if o in ("-p",=20
"--port"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
port =3D a</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # To -=20
the address to send the e-mail =
to<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
if o in ("-t",=20
"--to"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
towho =3D a</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # From -=20
the reply address<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if o in =
("-f",=20
"--from"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
fromwho =3D=20
a<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Username - the username =
to=20
login as if required<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if o =
in=20
("-u",=20
"--user"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
user =3D =
a<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Password - the password =
of the=20
smtp server if required<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if =
o in=20
("-p",=20
"--pass"):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
password =3D a</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Time -=20
amount of time in minutes to =
wait<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
if o in ("-w",=20
"--wait"):&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
wait =3D=20
int(a) * 60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; # Check for required =
and valid=20
command-line options<BR>&nbsp;&nbsp;&nbsp; if towho is=20
None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.stderr.write("To =
address=20
required.")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
usage(2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp; if=20
fromwho is None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
sys.stderr.write("From address=20
required.")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
usage(2)&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; if wait &lt;=20
300:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
sys.stderr.write("Invalid=20
wait value.")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
usage(2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; # Now we loop, checking the current address of =
the=20
machine against the address stored<BR>&nbsp;&nbsp;&nbsp; # in the =
file.&nbsp; If=20
we have a new address, we store that address in the file and=20
report<BR>&nbsp;&nbsp;&nbsp; # the new address by e-mail.&nbsp; We're =
depending=20
on Window's shutdown signal to stop<BR>&nbsp;&nbsp;&nbsp; #=20
properly<BR>&nbsp;&nbsp;&nbsp; while=20
(1):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newaddy =3D=20
get_addy()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if addy !=3D=20
newaddy:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
print "New addy: ",=20
newaddy<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; f=20
=3D open("ipwatch.dat",=20
"w")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
f.write(newaddy)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
f.close()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
s =3D smtplib.connect(smtpaddy,=20
port)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;=20
if user is not=20
None:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
s.login(user,=20
password)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
except=20
SMTPAuthenticationError:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
sys.stderr.write("Error logging into SMTP server.&nbsp; Check username =
and=20
password and=20
re-attempt")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
s.sendmail(towho, fromwho,=20
newaddy)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
s.quit()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; except=20
SMTPException,=20
reason:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
sys.stderr.write("SMTP Error: %s",=20
(reason))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
addy =3D newaddy<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
"The current=20
address is", addy<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
time.sleep(wait)&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;=20
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>if __name__ =3D=3D =
"__main__":<BR>&nbsp;&nbsp;&nbsp;=20
main()<BR>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Joel</FONT></DIV></BODY></HTML>

------=_NextPart_000_001E_01C228D9.50324040--