Python脚本没有结果

时间:2013-03-20 03:31:35

标签: python function

在修改sys.argv输入节之前,这个脚本正在使用一个提供输入的静态文件......不是出于某种原因我无法弄清楚...当我用两个参数运行脚本时./scriptname vuln_banners它只是退出。

#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python
import socket
import sys
import os
def retBanner(ip, port):
    try:
        socket.setdefaulttimeout(2)
        s = socket.socket()
        s.connect((ip, port))
        banner = s.recv(1024)
        return banner
    except:
        return
def checkVulns(banner, filename):
    f = open(filename, 'r')
    for line in f.readlines():
        if line.strip('\n') in banner:
            print '[-] Server is vulnerable:'+ banner.strip('\n')
def main():
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        if not os.path.isfile(filename):
            print '[-] ' + filename + ' does not exist'
            exit(0)
            if not os.access(filename, os.R_OK):
                print '[-] '+ filename + 'Access Denied'
                exit(0)
    else:
        print '[-] Usage: ' + str(sys.argv[0]) + '<vuln-filename>'
        exit(0)
        portList = [21,22,25,80,110]
        for x in range(1, 100):
            ip = '172.17.1.'+ str(x)
            for port in portList:
                print 'Checking ' + str(ip) + ' on port '+ str(port)
                banner = retBanner(ip, port)
                if banner:
                    print '[+] ' + ip + ': ' + banner
                    checkVulns(banner, filename)
if __name__ == '__main__':
    main()

0 个答案:

没有答案