[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
pseudocode:


###
def monitorAndReportIPChanges():
    ip = getIP()
    while 1:
        new_ip = getIP()
        if ip != new_ip:
            reportThatTheIpChanged()
        else:
            waitForSomeTime()
###


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

    http://www.python.org/doc/lib/module-time.html#l2h-1298

and the smtplib email module:

    http://www.python.org/doc/lib/module-smtplib.html

useful for you.


Hope this helps!