#!/usr/bin/python2
import urllib, re

try:
  tor_check = urllib.urlopen("http://check.torproject.org").read()
  ip = re.search("Your IP address appears to be:\s+<[^>]+>([^<]+)", tor_check).group(1)
  if "Congratulations" in tor_check:
    print ip
  else:
    print "\005{R}%s" % ip

except:
  print "error getting ip"
