Detect IP changes
Nagy László Zsolt
nagylzs at freemail.hu
Thu Mar 20 16:11:03 CET 2003
>Is there a reliable way to detect the change of a dynamic IP address ?
>If I use socket.gethostbyname('my_dynip_name') I still get the old IP, even
>thougt my system's DNS has been refreshed with the new name-address binding
>A solution should be platform independent.
>Thanks for your answers!
It seems you are having the same problems I was having.. :-)
You can use this module below. You must have an active internet connection
to load it. Call the getmyip() function to get your ip address. On
it will return the IP address of your external (internet) connection.
"""Get IP address towards external addresses"""
UPDATE_INTERVAL = 5 # Update cached ip in every 60 minutes.
COMMON_HOST = 'www.google.com'
COMMON_PORT = 80
_lock = threading.Lock()
_cached_ip = None
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ip = s.getsockname()
_cached_ip = ip
More information about the Python-list