Guest User

Untitled

a guest
Dec 5th, 2015
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import shodan
  4. import nmap
  5. import json
  6. import os
  7. import shlex, subprocess
  8.  
  9. nm = nmap.PortScanner()
  10.  
  11. SHODAN_API_KEY = "bdFoj87H00AoW7I3VfBA7d6Bfn6DV5jt"
  12.  
  13. api = shodan.Shodan(SHODAN_API_KEY)
  14.  
  15. # Wrap the request in a try/ except block to catch errors
  16. try:
  17. # Search Shodan
  18. results = api.search('cisco')
  19. # Show the results
  20. print 'Results found: %s' % results['total']
  21. #for result in results['matches']
  22. for result in results['matches'][:5]:
  23. print 'IP: %s' % result['ip_str']
  24. ipstr=result['ip_str']
  25. #ipstr='46.37.62.170'
  26. #print ipstr
  27. command = ('sudo nmap -sSV {}'.format(ipstr))
  28. #print command
  29. output = os.popen(command).readlines()
  30. #print output
  31. #print output
  32. #cmd = "/usr/bin/nmap -sSV --script ip-check --script-args=ip-check.result['ip_str'], --privileged"
  33. #args = shlex.split(cmd)
  34. #output = subprocess.check_output(args)
  35. #print output
  36. for line in output:
  37. words = line.split()
  38. if len(words) > 2:
  39. port, status, service = words[:3]
  40. if status == 'open':
  41. print(port, status, service)
  42.  
  43.  
  44. except shodan.APIError, e:
  45. print 'Error: %s' % e
Advertisement
Add Comment
Please, Sign In to add comment