Advertisement
0xspade

Reverse IP Lookup

Jan 17th, 2018
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import urllib2, urllib, sys, json
  4. from optparse import OptionParser
  5.  
  6.  
  7. # Terminal Colors
  8.  
  9. class bc:
  10.     P = '\033[95m' # purple
  11.     B = '\033[94m' # Blue
  12.     G = '\033[92m' # Green
  13.     Y = '\033[93m' # Yellow
  14.     R = '\033[91m' # Red
  15.     ENDC = '\033[0m' # end colors
  16.  
  17. if sys.platform == 'win32':
  18.     bc.P = ''
  19.     bc.B = ''
  20.     bc.G = ''
  21.     bc.Y = ''
  22.     bc.R = ''
  23.     bc.ENDC = ''
  24.  
  25. # End of terminal colors
  26.  
  27.  
  28. url = "https://domains.yougetsignal.com/domains.php"
  29.  
  30. contenttype = "application/x-www-form-urlencoded; charset=UTF-8"
  31.  
  32. def banner():
  33.     print bc.B +\
  34. """+-----------------------------------+
  35. |         Reverse IP Lookup         |
  36. |           By: Joinse7en           |
  37. +-----------------------------------+""" + bc.ENDC
  38.  
  39. def parseArgs():
  40.     # optionparser is kinda gay, will probably change
  41.     parser = OptionParser()
  42.  
  43.     parser.add_option("-t", "--target", dest="target",
  44.                       help="Domain or IP to reverse IP lookup", metavar="TARGET")
  45.  
  46.     parser.add_option("-p", "--proxy", dest="proxy",
  47.                       help="HTTPS proxy to use", metavar="PROXY")
  48.  
  49.     parser.add_option("-a", "--agent", dest="agent",
  50.                       help="Custom User Agent", metavar="AGENT")
  51.  
  52.    
  53.  
  54.     return parser
  55.  
  56. def request(target, httpsproxy=None, useragent=None):
  57.     global contenttype
  58.  
  59.     if not useragent:
  60.         useragent = "Mozilla/5.0 (X11; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0 Iceweasel/22.0"
  61.     else:
  62.         print "["+ bc.G + "+" + bc.ENDC + "] User-Agent: " + useragent
  63.  
  64.     if httpsproxy:
  65.         print "["+ bc.G + "+" + bc.ENDC + "] Proxy: " + httpsproxy + "\n"
  66.         opener = urllib2.build_opener(
  67.                 urllib2.HTTPHandler(),
  68.                 urllib2.HTTPSHandler(),
  69.                 urllib2.ProxyHandler({'http': 'http://' + httpsproxy}))
  70.         urllib2.install_opener(opener)
  71.  
  72.     postdata = [('remoteAddress',target),('key','')]
  73.     postdata = urllib.urlencode(postdata)
  74.  
  75.     request = urllib2.Request(url, postdata)
  76.  
  77.     request.add_header("Content-type", contenttype)
  78.     request.add_header("User-Agent", useragent)
  79.     try:
  80.         result = urllib2.urlopen(request).read()
  81.     except urllib2.HTTPError, e:
  82.         print "Error: " + e.code
  83.     except urllib2.URLError, e:
  84.         print "Error: " + e.args
  85.  
  86.     obj = json.loads(result)
  87.     return obj
  88.  
  89.  
  90. def output(obj):
  91.     print bc.B + "Status:    " +bc.ENDC + obj["status"]
  92.     if obj["status"] == "Fail":
  93.         message = obj["message"].split(". ")
  94.         print bc.R + "Error:     " + bc.ENDC + message[0] + "."
  95.         sys.exit(1)
  96.  
  97.     print bc.B+ "Domains:   " +bc.ENDC+ obj["domainCount"]
  98.     print bc.B+ "Target:    " +bc.ENDC+ obj["remoteAddress"]
  99.     print bc.B+ "Target IP: " +bc.ENDC+ obj["remoteIpAddress"]
  100.  
  101.     print "\n" + bc.P + "Results:" + bc.ENDC
  102.  
  103.     for domain, hl in obj["domainArray"]:
  104.         print bc.G + domain + bc.ENDC
  105.  
  106.  
  107. def main():
  108.     banner()
  109.     parser = parseArgs()
  110.     (options, args) = parser.parse_args()
  111.  
  112.     if len(sys.argv) < 2:
  113.         parser.print_help()
  114.         print "Examples:\n"
  115.         print sys.argv[0] + " --target domain.com"
  116.         print sys.argv[0] + " --target domain.com --proxy 192.168.0.1:8080"
  117.         print sys.argv[0] + " --target domain.com --agent \"Googlebot/2.1 (+http://www.googlebot.com/bot.html)\""
  118.  
  119.         sys.exit()
  120.  
  121.     target = options.target
  122.     print "\n"
  123.     obj = request(target, options.proxy, options.agent)
  124.     output(obj)
  125.  
  126.  
  127. if __name__ == "__main__":
  128.     try:
  129.         main()
  130.     except KeyboardInterrupt:
  131.         print "["+ bc.R + "!" + bc.ENDC + "] KeyboardInterrupt detected!\nGoodbye..."
  132.         sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement