Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:57:00+00:00 2026-06-03T05:57:00+00:00

I have SSH running on a machine with ADSL connection. I made this script

  • 0

I have SSH running on a machine with ADSL connection. I made this script to send me an email each time the machine has new a IP address.

The machine is not accessible by me. I gave the script to a friend so I cannot perform debugging to figure out what is wrong with this script. I’m using a university connection right now and it has a static ip address. There is no point running the script on it.

So any suggestions how to improve/fix the script. Sometimes I’ll receive non valid IP addresses or sometimes the IP address will change but I don’t get an email. Should I use another method for this kind of automation?

import urllib
import time
import smtplib

fromaddr = '***@gmail.com'  
toaddrs  = '***@gmail.com'    
ip = ""

username = '****'  
password = '****'  
f = False

def update():
    global ip,f
    #print "sleeping 5 seconds"
    time.sleep(5)
    while not f:
        try:
            f = urllib.urlopen("http://automation.whatismyip.com/n09230945.asp")
        except IOError, e:
            print "no internet !"
            time.sleep(5)

    if not ip and f:
        ip = f.read()
        print "getting the first ip"
        print ip
        sendmail(ip)
        print "mail sent"

    else:
        if f:
            ip2 = f.read()
            #print ip,ip2
            if ip != ip2 and ip and ip2:
                ip = ip2
                print "new ip",ip,"sending mail"
                sendmail(ip)
            else:
                print "ip is the same"
            f = False
    #print ip

def sendmail(ip):
    a = False
    while not a:
        try:
            #just to check if i have internet or not
            a = urllib.urlopen("http://automation.whatismyip.com/n09230945.asp")
            server = smtplib.SMTP('smtp.gmail.com:587')
            server.ehlo()
            server.starttls()
            server.ehlo()
            server.login(username,password)
            server.sendmail(fromaddr, toaddrs, ip)  
            server.quit()
        except IOError, e:
            print "no internet"
            time.sleep(5)
            #sendmail(ip)


print "program started"

while(1):
    update()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:57:01+00:00Added an answer on June 3, 2026 at 5:57 am

    I’d suggest that you might be hitting the server too often and getting blocked… http://forum.whatismyip.com/f14/pace-yourself-t6/

    Change your first time.sleep(5) to time.sleep(300).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, i'm running emacs over a crappy ssh connection and I have it set
I have a bash script that does ssh to a remote machine and executes
I have a small machine running Debian and can access it via ssh -l
Need a way to have a perl script running on one machine run a
I have Cygwin running on a Windows 7 machine and have the Cygwin ssh
I have ssh'ed to a remote machine and started emacs. I opened one small
I have a command that runs fine if I ssh to a machine and
On my local machine I have an SSH tunnel setup for postgres like so:
I have ssh-ed to a remote machine. I have enabled X11 forwarding (ssh -X)
I have two ubuntu linux boxes: I'm in bash on one machine running some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.