Advertisement
Guest User

Untitled

a guest
Aug 6th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. import sys
  2. import urllib2
  3. import commands
  4. import struct
  5. from binascii import unhexlify, crc32
  6.  
  7. # usage, python script.py address
  8. addr = str(sys.argv[1])
  9.  
  10. def txdecode(transaction):
  11.  
  12. data = urllib2.urlopen("https://blockchain.info/tx/"+transaction+"?show_adv=true")
  13. dataout = b''
  14. atoutput = False
  15.  
  16. for line in data:
  17. if 'Output Scripts' in line:
  18. atoutput = True
  19. if '</table>' in line:
  20. atoutput = False
  21. if atoutput:
  22. if len(line) > 100:
  23. chunks = line.split(' ')
  24. for c in chunks:
  25. if 'O' not in c and '\n' not in c and '>' not in c and '<' not in c:
  26. dataout += unhexlify(c.encode('utf8'))
  27.  
  28. length = struct.unpack('<L', dataout[0:4])[0]
  29. checksum = struct.unpack('<L', dataout[4:8])[0]
  30. dataout = dataout[8:8+length]
  31.  
  32. return dataout
  33.  
  34. print 'Reading '+addr+"'s transactions..."
  35. offset = 0
  36. startatpage = 0 #17
  37. offset = startatpage*50
  38. data = urllib2.urlopen("https://blockchain.info/address/"+addr+"?offset="+str(offset)+"&filter=0")
  39.  
  40. pagecalc = offset/50
  41. if pagecalc == 0:
  42. pagecalc = 1
  43.  
  44. page = pagecalc
  45. files = 0
  46. keep_reading = True
  47. tx_list = []
  48. f = open('dataout/'+addr+"_tx_list.txt", 'w')
  49.  
  50. while (keep_reading):
  51. tx_exist = False
  52.  
  53. if keep_reading:
  54. print 'Page', page, '...'
  55. data = urllib2.urlopen("https://blockchain.info/address/"+addr+"?offset="+str(offset)+"&filter=0")
  56. for line in data:
  57. chunks = line.split('><')
  58. if 'hash-link' in line:
  59. tx_exist = True
  60. ll = chunks[4].split(' ')
  61. #print 'll', len(ll)
  62. if len(ll) == 1:
  63. continue
  64. #print ll
  65. #print 'll2', len(ll[2])
  66. lll = ll[2][10:10+64]
  67.  
  68. date1 = ll[4].split('>')[1]
  69. date2 = ll[5].split('<')[0]
  70. print date1, date2
  71.  
  72. print lll
  73. f.write(str(lll)+'\n')
  74.  
  75. decoded_data = txdecode(str(lll))
  76. fd = open('dataout/'+str(lll),"wb")
  77. fd.write(decoded_data)
  78. fd.close()
  79.  
  80. status, output = commands.getstatusoutput("dataout/trid dataout/"+str(lll))
  81. if 'Unknown!' not in output:
  82.  
  83. ff = open('dataout/'+addr+"_file_tx_list.txt", 'a')
  84. files += 1
  85. outputlines = output.split('\n')
  86. for i in range(6,len(outputlines)):
  87. print outputlines[i]
  88. ff.write(str(lll)+' '+outputlines[6]+' '+date1+' '+date2+'\n')
  89. ff.close()
  90.  
  91. page += 1
  92. offset += 50
  93. if tx_exist == False:
  94. keep_reading = False
  95.  
  96. print len(tx_list), 'transactions found'
  97. print files, 'file headers found'
  98. print 'List saved in file', addr+"_tx_list.txt"
  99. print 'Txs with file headers saved in', addr+"_file_tx_list.txt"
  100. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement