1

I have written a python script to search through shodan, my script code returns a file containing an ip list that each line contains single ip. here is my code:

import shodan
SHODAN_API="YOUR_SHODAN_API"
api = shodan.Shodan(SHODAN_API)
try:
    # Search Using Shodan
    results = api.search('EXAMPLE')

    # Showing the results
    print 'Results found: %s' % results['total']
    for result in results['matches']:
        print '%s' % result['ip_str']
    ''' following lines could be uncommented due to more information
    Don't Uncomment if you are using scanning methods with the results '''
        #print result['data']
        #print ''
except shodan.APIError, e:
    print 'Error: %s' % e

I was wondering if there is any way to automate the task of running my code and then scanning the ip list by external script or something that work on OSX and Linux ?

Ashkan
  • 378
  • 1
  • 18
SomeGuyBig
  • 15
  • 6

2 Answers2

2

You can simply use a bash script like the following one:

#!/bin/bash
python ShodanSearch.py >> IPResult.txt
cat IPResult.txt | while read line
do
sudo nmap -n -Pn -sV -p 80,8080 -oG - $line >> NResult.txt
done
SomeGuyBig
  • 15
  • 6
Ashkan
  • 378
  • 1
  • 18
  • Thank you for your time but just how can i use it ? – SomeGuyBig Aug 05 '20 at 17:13
  • 1
    Simply Create a new file called "whatever.sh" and put this code inside it, then run it by typing ```bash whatever.sh``` in terminal or ```./whatever.sh``` – Ashkan Aug 05 '20 at 17:16
0

As an alternative to the solution above, you could also execute nmap using the python os module to execute shell commands within your python script, or the now preferred method is with the subprocess module, haven’t personally used the latter, but it can definitely do what you want.

NeelD
  • 73
  • 9