Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import shodan
- import nmap
- import json
- import os
- import shlex, subprocess
- nm = nmap.PortScanner()
- SHODAN_API_KEY = "bdFoj87H00AoW7I3VfBA7d6Bfn6DV5jt"
- api = shodan.Shodan(SHODAN_API_KEY)
- # Wrap the request in a try/ except block to catch errors
- try:
- # Search Shodan
- results = api.search('cisco')
- # Show the results
- print 'Results found: %s' % results['total']
- #for result in results['matches']
- for result in results['matches'][:5]:
- print 'IP: %s' % result['ip_str']
- ipstr=result['ip_str']
- #ipstr='46.37.62.170'
- #print ipstr
- command = ('sudo nmap -sSV {}'.format(ipstr))
- #print command
- output = os.popen(command).readlines()
- #print output
- #print output
- #cmd = "/usr/bin/nmap -sSV --script ip-check --script-args=ip-check.result['ip_str'], --privileged"
- #args = shlex.split(cmd)
- #output = subprocess.check_output(args)
- #print output
- for line in output:
- words = line.split()
- if len(words) > 2:
- port, status, service = words[:3]
- if status == 'open':
- print(port, status, service)
- except shodan.APIError, e:
- print 'Error: %s' % e
Advertisement
Add Comment
Please, Sign In to add comment