pyvisitor.py


SUBMITTED BY: Guest

DATE: May 18, 2014, 8:21 p.m.

FORMAT: Text only

SIZE: 7.2 kB

HITS: 1133

  1. '''
  2. Requires Beautiful Soup
  3. usage: pyvisitor.py [-h] [-u path] [-a address] (all arguments are optional)
  4. optional arguments:
  5. -h, --help Show this help message and exit.
  6. -u path, --user-agents path A path to a file containing a user-agent on each line.
  7. -a address, --address address Your bitcoin address. If omitted, you will be prompted.
  8. '''
  9. from PIL import Image, ImageTk
  10. from Tkinter import Tk, Entry, Label
  11. from argparse import ArgumentParser
  12. from bs4 import BeautifulSoup
  13. from cStringIO import StringIO
  14. from cookielib import CookieJar
  15. from random import randrange, choice
  16. from time import sleep
  17. from urllib import urlencode
  18. from urllib2 import urlopen, Request, HTTPCookieProcessor, install_opener, build_opener, URLError
  19. class InputWindow:
  20. def __init__(self, container, img=None, p=None):
  21. root = Tk()
  22. root.attributes('-topmost', 1)
  23. hint = '(Enter - submit, Esc - abort)'
  24. if img is None:
  25. root.wm_title('Address')
  26. hint = 'Please enter your Bitcoin address.\n' + hint
  27. else:
  28. root.wm_title('Captcha {0:g}'.format(p))
  29. img = ImageTk.PhotoImage(img)
  30. root.img_reference = img
  31. image = Label(root, image=img, text=hint, compound='top')
  32. image.pack()
  33. entry = Entry(root)
  34. entry.bind('<Escape>', lambda _:root.destroy())
  35. entry.bind('<Return>', lambda _:(container.setdefault(0, (entry.get())), root.destroy()))
  36. entry.pack()
  37. entry.focus_set()
  38. root.update_idletasks()
  39. xp = (root.winfo_screenwidth() / 2) - (root.winfo_width() / 2) - 8
  40. yp = (root.winfo_screenheight() / 2) - (root.winfo_height() / 2) - 20
  41. root.geometry('+%d+%d' % (xp, yp))
  42. root.mainloop()
  43. class PyVisitor:
  44. def __init__(self, address=None, agentFile=None):
  45. self.__addr = address
  46. if not address:
  47. address = {}
  48. InputWindow(address)
  49. if not address.get(0):
  50. print 'Aborted by user.'
  51. exit(0)
  52. self.__addr = address[0]
  53. self.__currentProfit = .0
  54. self.__currency = ''
  55. self.__captchaURL = None
  56. self.__host = 'http://bitvisitor.com/'
  57. defaultAgent = 'Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.15'
  58. self.__headers = {'Accept':'text/html,application/xhtml+xml,application/xml',
  59. 'User-Agent':defaultAgent}
  60. install_opener(build_opener(HTTPCookieProcessor(CookieJar())))
  61. if agentFile:
  62. try:
  63. with open(agentFile) as f:
  64. self.__headers['User-Agent'] = choice([agent.rstrip() for agent in f])
  65. except:
  66. print 'Using default User-Agent.'
  67. print 'User-Agent:', self.__headers['User-Agent']
  68. print 'Bitcoin address:', self.__addr
  69. def __getCaptchaURL(self, soup):
  70. captchaImg = soup.find('img', id='siimage')
  71. if not captchaImg:
  72. return
  73. earning = soup.find('h1', 'page-header').contents[1].split()
  74. self.__currentProfit = float(earning[0])
  75. self.__currency = earning[1]
  76. self.__captchaURL = self.__host + captchaImg['src'].lstrip('./')
  77. return self.__captchaURL
  78. def __wait(self, soup):
  79. siteFrame = soup.find('iframe', id='mlsFrame')
  80. if not siteFrame: return
  81. print 'Visiting', siteFrame['src']
  82. print 'Getting {0:g} {1} in'.format(self.__currentProfit, self.__currency),
  83. for i in range(5, 0, -1):
  84. print i,
  85. sleep(60)
  86. print
  87. sleep(randrange(1, 10)) # just to be sure ;)
  88. def visit(self):
  89. req = Request(self.__host, None, self.__headers)
  90. res = urlopen(req) # set session cookie
  91. if 'abuse' in res.geturl():
  92. print 'ERROR: The IP address was deemed suspicious.'
  93. return
  94. # The following address stands for a referral link. Right now it points to my address.
  95. # Feel free to change it to whatever you like when you redistribute the source code.
  96. # FYI, the original author's address is 13QgXZGtXYEY9cnEB9mGuD1ZbXMWirTicg.
  97. # Make sure to thank him with a small donation.
  98. params = urlencode({'addr':self.__addr, 'ref':'1HKoN8Y4xZVsLmVx3eqFf8pb3Qyskm79nh'})
  99. url = self.__host + 'next.php'
  100. self.__headers['Referer'] = url
  101. req = Request(url, params, self.__headers)
  102. while True:
  103. res = urlopen(req)
  104. if 'abuse' in res.geturl():
  105. print 'ERROR: The IP address was deemed suspicious.'
  106. break
  107. soup = BeautifulSoup(res.read())
  108. if not self.__getCaptchaURL(soup): break
  109. a = None
  110. while not a:
  111. captcha = {}
  112. InputWindow(captcha, Image.open(StringIO(urlopen(self.__captchaURL).read())), self.__currentProfit)
  113. if not captcha.get(0):
  114. print 'Aborted by user.'
  115. break
  116. cParams = urlencode({'ct_captcha':captcha[0], 'addr':self.__addr})
  117. soup = BeautifulSoup(urlopen(Request(url, cParams, self.__headers)).read())
  118. form = soup.find('form', action='next.php')
  119. if not form:
  120. message = soup.get_text()
  121. if 'Incorrect' in message: continue
  122. print message
  123. break
  124. a = form.find('input', {'name':'a'})['value']
  125. t = form.find('input', {'name':'t'})['value']
  126. if a and t:
  127. break
  128. if not a: # aborted by user or site error
  129. break
  130. self.__wait(soup)
  131. nParams = urlencode({'addr':self.__addr, 'a':a, 't':t})
  132. res = urlopen(Request(url, nParams, self.__headers))
  133. if not res:
  134. break
  135. print 'Earned {0:g} {1}'.format(self.__currentProfit, self.__currency)
  136. def main():
  137. parser = ArgumentParser()
  138. parser.add_argument('-u', '--user-agents', metavar='path',
  139. help='A path to a file containing a user-agent on each line.')
  140. parser.add_argument('-a', '--address', metavar='address',
  141. help='Your bitcoin address. If omitted, you will be prompted.')
  142. ns = parser.parse_args()
  143. try:
  144. PyVisitor(ns.address, ns.user_agents).visit()
  145. except URLError as e:
  146. print str(e)
  147. if __name__ == "__main__":
  148. main()

comments powered by Disqus