【问题标题】:How to run a python file and scan the generated ips by nmap如何运行python文件并通过nmap扫描生成的ips
【发布时间】:2020-11-25 22:12:01
【问题描述】:

我编写了一个 python 脚本来搜索 shodan,我的脚本代码返回一个文件,其中包含一个 ip 列表,每行包含一个 ip。 这是我的代码:

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

我想知道是否有任何方法可以自动运行我的代码,然后通过外部脚本或在 OSX 和 Linux 上工作的东西扫描 ip 列表?

【问题讨论】:

    标签: linux macos python-2.7 shodan


    【解决方案1】:

    您可以简单地使用如下所示的 bash 脚本:

    #!/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
    

    【讨论】:

    • 感谢您的宝贵时间,但我该如何使用它?
    • 只需创建一个名为“whatever.sh”的新文件并将此代码放入其中,然后在终端中键入bash whatever.sh./whatever.sh 运行它
    【解决方案2】:

    作为上述解决方案的替代方案,您还可以使用 python os 模块执行 nmap 以在您的 python 脚本中执行 shell 命令,或者现在首选的方法是使用 subprocess 模块,没有亲自使用过后者,但是它绝对可以为所欲为。

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 2019-02-09
      • 2014-11-06
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多