
from socket import *
import os,sys


socket = socket(AF_INET, SOCK_STREAM)

def retbanner(ip,port):
    try:
        setdefaulttimeout(2)
        socket.connect((ip,port))
        banner = socket.recv(1024)
        return banner
    except:
        return 

def checkvulns(banner,filename):
    f= open (os.getcwd()+'/'+filename, 'r')
    for lines in f.readlines():
        print (lines)
        if (lines in banner) | (lines == banner):
            print ("[+] Server is vulnerable: " + banner.strip("\n"))
            exit(0) 

def main():
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        if not os.path.isfile(filename):
            print ('[-] File doesnt Exist!')
            exit(0)
        if not os.access(filename, os.R_OK):
            print ('[-] Access denied !')
            exit(0)
    else:
        print ("[+] Usage : "+ str(sys.argv[0] + " <vuln filename>"))
        exit(0)

    portlist = [22,25,45,60,445,443,80]
    ip = "192.168.31.162"
    for port in portlist:
        banner = retbanner(ip,port)
        if banner:
            print ("[+]" + ip + "/" + str(port) + " : " + banner.strip('\n'))
            checkvulns(banner, filename)

if __name__ == '__main__':
    main()          



# o/p: Enter the IP :192.168.31.162
# [+]192.168.31.162/25 : 220 caavo-Inspiron-3542 ESMTP Postfix (Ubuntu)