sirnon

emingoo.py

Aug 16th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. # Name: emingoo.py
  4. # Version: 1.0
  5. # Author: pantuts
  6. # Email: contact@pantuts.com
  7. # Description: Extract emails from Google search results.
  8. # Agreement: You can use, modify, or redistribute this tool under the terms of GNU General Public License (GPLv3).
  9. # This tool is for educational purposes only. Any damage you make will not affect the author.
  10.  
  11. import sys, re, time
  12. from urllib.request import Request, urlopen
  13. import urllib.error
  14.  
  15. def helper():
  16. print('Usage:./emingoo.py -d domainToSearch -c maxResults[int]')
  17. print('Default min google search result is 100 and max is 10000.')
  18. print()
  19.  
  20. def extract(res, d):
  21. em_sub = re.sub('<[^<]+?>', '', res) # strip all html tags like <em>
  22. tmp_emails = re.findall(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9._%+-]+' + d, em_sub)
  23. tmp_emails1 = re.findall(r'[a-zA-Z0-9._%+-]+@' + d, em_sub)
  24. tmp_emails2 = set(tmp_emails + tmp_emails1)
  25. emails = [x for x in tmp_emails2]
  26. if len(emails) == 0: print('Sorry, no results found.')
  27. else:
  28. for i in emails: print(i); time.sleep(0.01)
  29. print()
  30.  
  31. def crawl(d, c):
  32. if c > 10000:
  33. print('Sorry your argument -c exceeded on its max search result.')
  34. sys.exit(0)
  35. print('Searching emails for ' + d + ' ...')
  36. print()
  37. try:
  38. q = 'http://www.google.com/search?hl=en&num=' + str(c) + '&q=intext%3A%40' + d + '&ie=utf-8'
  39. req = Request(q)
  40. req.add_header('User-Agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0')
  41. res = urlopen(req).read().decode('utf-8')
  42. except (urllib.error.URLError, urllib.error.HTTPError) as e:
  43. print(e)
  44. sys.exit(1)
  45.  
  46. extract(res, d)
  47.  
  48. def main():
  49. if len(sys.argv) < 3 or len(sys.argv) > 5:
  50. helper()
  51. sys.exit(0)
  52. else:
  53. if len(sys.argv) == 5:
  54. domain = sys.argv[2]
  55. max_res = int(sys.argv[4])
  56. elif len(sys.argv) == 3:
  57. domain = sys.argv[2]
  58. max_res = 100
  59. else:
  60. helper()
  61. sys.exit(0)
  62.  
  63. crawl(domain, max_res)
  64.  
  65. if __name__=='__main__':
  66. print(' ____ __ __ ____ _ _ ___ _____ _____ ')
  67. print('( ___)( \/ )(_ _)( \( )/ __)( _ )( _ )')
  68. print(' )__) ) ( _)(_ ) (( (_-. )(_)( )(_)( ')
  69. print('(____)(_/\/\_)(____)(_)\_)\___/(_____)(_____)')
  70. print()
  71. try:
  72. main()
  73. except KeyboardInterrupt:
  74. print('\rKeyboardInterrupt')
  75. sys.exit(0)
Add Comment
Please, Sign In to add comment