Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import shodan
  5. import sys
  6. import os
  7. import threading
  8.  
  9. #python xx.py product:IIS version:"6.0"
  10.  
  11. # Configuration
  12. API_KEY = "rj8iYTWES8TttT3Ykp0K3MMDCEOVUtAh"
  13. #API_KEY = "pHHlgpFt8Ka3Stb5UlTxcaEwciOeF2QM"
  14.  
  15. def crawler():
  16. # Input validation
  17. if len(sys.argv) == 1:
  18. print 'Usage: %s <search query>' % sys.argv[0]
  19. sys.exit(1)
  20.  
  21. try:
  22.  
  23. #api = shodan.Shodan(API_KEY)
  24.  
  25. # Perform the search
  26. query = ' '.join(sys.argv[1:])
  27.  
  28. for i in range(1,2):
  29. threading.Thread(target=shodanthread,args=(i,query,)).start()
  30.  
  31. except Exception as e:
  32. print 'Error: %s' % e
  33. sys.exit(1)
  34.  
  35. def shodanthread(i,query):
  36. # Setup the api
  37. api = shodan.Shodan(API_KEY)
  38. result = api.search(query,page=10,limit=200,offset=(i-1)*200)
  39.  
  40. # Loop through the matches and print each IP
  41. for service in result['matches']:
  42. ip = service['ip_str']
  43.  
  44. country_code = service['location']['country_code']
  45. domains = service['domains']
  46. Location = service['http']['redirects']['Location']
  47. port = service['port']
  48. org = service['org']
  49. server = service['server']
  50.  
  51. if country_code != 'CN':
  52. with open('urlresult', 'a') as f:
  53. f.write(ip+"--"+str(port)+"--"+str(domains)+"--"+country_code+"--"+org+"--"+server+"--"+Location+"\n")
  54.  
  55.  
  56. if __name__ == '__main__':
  57. crawler()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement