[Tutor] IP Address

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 23 Aug 2001 21:04:17 -0700 (PDT)

On Thu, 23 Aug 2001, Jordan Stanley wrote:

> am trying to implement a script to have my server email me my ip
> address every time it changes.
> any thoughts? suggestions?

One way to do this is to do a "busy waiting" approach: have your program
check every so often if your IP has changed or not.  If it has, send off
the message.  Otherwise, wait for a while, and try again.  Here's some

def monitorAndReportIPChanges():
    ip = getIP()
    while 1:
        new_ip = getIP()
        if ip != new_ip:

If you do it this way, you may find the time.sleep() function:


and the smtplib email module:


useful for you.

Hope this helps!