#!/usr/bin/env python
# works in both Python 2 and Python 3
import re,miniupnpc
u = miniupnpc.UPnP()
u.discoverdelay=200;u.discover()
u=u.selectigd()
u=re.sub(':[0-9]+/.*','',u)
try: from urllib2 import build_opener, HTTPError, HTTPRedirectHandler # Python 2
except: from urllib.request import build_opener, HTTPError, HTTPRedirectHandler # Python 3
class DoNotRedirect(HTTPRedirectHandler):
    def http_error_302(*args): pass
    http_error_301 = http_error_303 = http_error_307 = http_error_302
try: u = build_opener(DoNotRedirect).open(u)
except HTTPError as e: u=e
date = u.headers["Date"]
if date.endswith("GMT"): date=date[:-3].rstrip() # some routers have local time but incorrectly call it GMT
print(date.replace(", "," "))
