Advertisement
Guest User

Untitled

a guest
May 5th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. import urllib2
  2. from base64 import b64encode
  3. import os
  4. import sys
  5. import time
  6.  
  7. today = time.strftime('%Y-%m-%d_%H-%M-%S')
  8.  
  9. with open('nwfcdlc.txt') as file:
  10. codes = file.readlines()
  11.  
  12. for line in codes:
  13. line = line.split('#')[0] # remove comments
  14. data = line.split()
  15.  
  16. try:
  17. gamecode = data[0]
  18. realgamecode = data[1]
  19. password = data[2]
  20. except:
  21. continue
  22.  
  23.  
  24.  
  25. ###Get token
  26. url = "http://nas.nintendowifi.net/ac"
  27. headers = { 'User-Agent' : 'Nitro WiFi SDK/3.1', 'Content-type' : 'application/x-www-form-urlencoded', 'HTTP_X_GAMECD' : gamecode }
  28. data = "action=bG9naW4*&gsbrcd=QzZQRTBjdTdvaGs*&sdkver=MDAzMDAx&userid=Nzg4MTk4NjAyOTYzMQ**&passwd=Mjk3&bssid=MDBmMDFhMmIzYzRk&apinfo=MDA6MDAwMDAwMC0wMA**&gamecd=" + b64encode(gamecode) + "&makercd=MDE*&unitcd=MA**&macadr=MDAxNjU2ODMzMWY5&lang=MDE*&birth=MDcwYw**&devtime=MTQwNDI5MTkyMjEx&devname=UABhAFIAYQBEAG8AWAA*"
  29.  
  30. req = urllib2.Request(url, data, headers)
  31. response = urllib2.urlopen(req)
  32. the_page = response.read()
  33.  
  34. #open('out1.bin','w').write(the_page)
  35.  
  36. data = "sdkver=MDAzMDAx&userid=Nzg4MTk4NjAyOTYzMQ**&passwd=Mjk3&bssid=MDBmMDFhMmIzYzRk&apinfo=MDA6MDAwMDAwMC0wMA**&gamecd=" + b64encode(gamecode) + "&makercd=MDE*&unitcd=MA**&macadr=MDAxNjU2ODMzMWY5&lang=MDE*&birth=MDcwYw**&devtime=MTQwNDI5MTkyMjE5&devname=UABhAFIAYQBEAG8AWAA*&action=U1ZDTE9D&svc=OTAwMA**"
  37.  
  38. req = urllib2.Request(url, data, headers)
  39. response = urllib2.urlopen(req)
  40. the_page = response.read()
  41.  
  42. #open('out2.bin','w').write(the_page)
  43.  
  44. token = the_page[the_page.find('vicetoken')+10:] #'servicetoken'
  45. token = token[:token.find('&')]
  46.  
  47.  
  48.  
  49. #Create output folder if it doesn't exist
  50. if not os.path.exists('./' + today ):
  51. os.makedirs('./'+today)
  52. if not os.path.exists('./'+today+'/'+realgamecode):
  53. os.makedirs('./'+today+'/'+realgamecode)
  54.  
  55.  
  56.  
  57. url = "https://dls1.nintendowifi.net/download"
  58. headers = { 'User-Agent' : 'Nitro WiFi SDK/3.1', 'Content-type' : 'application/x-www-form-urlencoded'}
  59.  
  60. ###List files
  61. data="gamecd=" + b64encode(gamecode) + "&rhgamecd=" + b64encode(realgamecode) + "&passwd=" + b64encode(password) + "&token=" + token + "&macadr=MDAxNjU2ODMzMWY5&action=" + b64encode('list') + "&apinfo=MDA6MDAwMDAwMC0wMA%2A%2A&offset=" + b64encode('0') + "&num=" + b64encode('999999')
  62.  
  63. req = urllib2.Request(url, data, headers)
  64. response = urllib2.urlopen(req)
  65. the_page = response.read()
  66.  
  67. open('./'+today+'/'+realgamecode+'/___listing___.bin','w').write(the_page) #Save the listing, it sometimes has additional data the game may need
  68.  
  69.  
  70.  
  71. ###Download files
  72. lines = the_page[:-1].split('\n')
  73. if len(lines) == 0:
  74. print "No files to download for game code " + realgamecode + ", quitting..."
  75. sys.exit()
  76. print "Game code " + realgamecode + " has " + str(len(lines)) + " files to download.\n"
  77.  
  78. for line in lines:
  79. fname = line[:line.find('\t')]
  80. if fname == '':
  81. continue
  82. print "Downloading " + fname + "..."
  83.  
  84. data="gamecd=" + b64encode(gamecode) + "&rhgamecd=" + b64encode(realgamecode) + "&passwd=" + b64encode(password) + "&token=" + token + "&userid=Nzg4MTk4NjAyOTYzMQ%2A%2A&macadr=MDAxNjU2ODMzMWY5&action=" + b64encode('contents') + "&apinfo=MDA6MDAwMDAwMC0wMA%2A%2A&contents=" + b64encode(fname)
  85.  
  86. req = urllib2.Request(url, data, headers)
  87. response = urllib2.urlopen(req)
  88. the_page = response.read()
  89.  
  90. open('./'+today+'/'+realgamecode+'/'+fname,'wb').write(the_page)
  91. print "Done!\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement