from bs4 import BeautifulSoup
import requests
import re

def look_up_cve(cve):

    url = 'https://www.cvedetails.com/cve-details.php?t=1&cve_id='+ cve
    r = requests.get(url=url)

    soup = BeautifulSoup(r.text, 'html.parser')


def look_up_nvd(cve):
    url = "https://web.nvd.nist.gov/view/vuln/detail?vulnId="+cve
    r = requests.get(url)

    soup= BeautifulSoup(r.text, 'html.parser')

    return soup.text

def find_cve(text):
    print "[] Locating CVE's"
    cve = re.findall(r'CVE-\d{4}-\d{4,7}', text)
    if not cve:
        print "][ no CVE's Found"
    return cve

def pull_advisory(url):

    print "[] pulling down advisory"

    r = requests.get(url)

    soup = BeautifulSoup(r.text, 'html.parser')

    return soup

def find_cpe(text):

    print "[]Finding CPE"

    cpe = re.findall(r"[aho](?::[a-zA-Z0-9!#$%&'()*+\\,\-_.\/;<=>?@\[\]^`{|}~]*){9,}", text)

    if not cpe:
        print "][ no CPE's found"

    return cpe

def main(url):
    cve = []


    text = pull_advisory(url)
    for vul in find_cve(text.text):
        cve.append(vul)
        cpe_list = []
        nvd = look_up_nvd(vul)

        for entity in find_cpe(nvd):
            full_cpe = "cpe:%s" %entity
            cpe_list.append(full_cpe)
        cve.append(cpe_list)

    print cve

if __name__ == '__main__':
    url = "https://msisac.cisecurity.org/advisories/2016/2016-163.cfm"
    main(url)
7342ec4e25a3755a75b093bdb0c653889887ef48
from bs4 import BeautifulSoup
import requests
import re

def look_up_cve(cve):

    url = 'https://www.cvedetails.com/cve-details.php?t=1&cve_id='+ cve
    r = requests.get(url=url)

    soup = BeautifulSoup(r.text, 'html.parser')


def look_up_nvd(cve):
    url = "https://web.nvd.nist.gov/view/vuln/detail?vulnId="+cve
    r = requests.get(url)

    soup= BeautifulSoup(r.text, 'html.parser')

    return soup.text

def find_cve(text):
    print "[] Locating CVE's"
    cve = re.findall(r'CVE-\d{4}-\d{4,7}', text)
    if not cve:
        print "][ no CVE's Found"
    return cve

def pull_advisory(url):

    print "[] pulling down advisory"

    r = requests.get(url)

    soup = BeautifulSoup(r.text, 'html.parser')

    return soup

def find_cpe(text):

    print "[]Finding CPE"

    cpe = re.findall(r"[aho](?::[a-zA-Z0-9!#$%&'()*+\\,\-_.\/;<=>?@\[\]^`{|}~]*){9,}", text)

    if not cpe:
        print "][ no CPE's found"

    return cpe

def main(url):
    cve = []


    text = pull_advisory(url)
    for vul in find_cve(text.text):
        cve.append(vul)
        cpe_list = []
        nvd = look_up_nvd(vul)

        for entity in find_cpe(nvd):
            full_cpe = "cpe:%s" %entity
            cpe_list.append(full_cpe)
        cve.append(cpe_list)

    print cve

if __name__ == '__main__':
    url = "https://msisac.cisecurity.org/advisories/2016/2016-163.cfm"
    main(url)