Get IP using 'urllib.request'
This commit is contained in:
parent
6945b5b8f4
commit
4195348125
|
@ -18,6 +18,8 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import smtplib
|
import smtplib
|
||||||
|
import urllib
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
#Check if your system use Python 3.x
|
#Check if your system use Python 3.x
|
||||||
if sys.version_info<(3,0):
|
if sys.version_info<(3,0):
|
||||||
|
@ -160,15 +162,14 @@ while PublicIP <= 2:
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
||||||
editlog=open('ip2e.log','a')
|
editlog=open('ip2e.log','a')
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP Updating...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP Updating...\n")
|
||||||
NewIPRaw = os.popen('curl -s icanhazip.com').read()
|
try:
|
||||||
NewIP = NewIPRaw.strip()
|
response = urllib.request.urlopen('http://icanhazip.com')
|
||||||
#NewIP = os.popen('curl -s http://ip.appspot.com/').read()
|
#response = urllib.request.urlopen('http://ip.appspot.com/')
|
||||||
#NewIP = os.popen('curl -s ident.me').read()
|
#response = urllib.request.urlopen('http://ident.me')
|
||||||
#NewIPRaw = os.popen('curl -s ifconfig.me').read()
|
NewIPRaw = response.read()
|
||||||
#NewIP = NewIPRaw.strip()
|
NewIP = NewIPRaw.strip().decode('utf-8')
|
||||||
if NewIP != "":
|
|
||||||
GetCurrentIP += 2
|
GetCurrentIP += 2
|
||||||
else:
|
except:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
RedColor()
|
RedColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user