From 4195348125c2e28c4e95cd5b74c98dd218ee1c31 Mon Sep 17 00:00:00 2001 From: clamsawd Date: Fri, 30 Oct 2015 17:31:42 +0100 Subject: [PATCH] Get IP using 'urllib.request' --- ip2e-daemon.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ip2e-daemon.py b/ip2e-daemon.py index fe6a367..184e6b7 100755 --- a/ip2e-daemon.py +++ b/ip2e-daemon.py @@ -18,6 +18,8 @@ import os import sys import time import smtplib +import urllib +import urllib.request #Check if your system use Python 3.x if sys.version_info<(3,0): @@ -160,15 +162,14 @@ while PublicIP <= 2: print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...") editlog=open('ip2e.log','a') editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP Updating...\n") - NewIPRaw = os.popen('curl -s icanhazip.com').read() - NewIP = NewIPRaw.strip() - #NewIP = os.popen('curl -s http://ip.appspot.com/').read() - #NewIP = os.popen('curl -s ident.me').read() - #NewIPRaw = os.popen('curl -s ifconfig.me').read() - #NewIP = NewIPRaw.strip() - if NewIP != "": + try: + response = urllib.request.urlopen('http://icanhazip.com') + #response = urllib.request.urlopen('http://ip.appspot.com/') + #response = urllib.request.urlopen('http://ident.me') + NewIPRaw = response.read() + NewIP = NewIPRaw.strip().decode('utf-8') GetCurrentIP += 2 - else: + except: CurrentTime = time.strftime("%H:%M") RedColor() print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")