2018-04-05 17:03:34 -05:00
#!/usr/bin/env ruby
# CVE class
2018-04-07 07:36:17 -05:00
# the end goal of this is to just be something that i can use to lookup cve quickly from the command line. yes i know that these tools already exist, but what i'm trying to learn more about ruby so why not?
2018-04-05 17:03:34 -05:00
require 'net/http'
class CVE
def base_uri
@base_uri || = 'https://nvd.nist.gov/feeds/'
end
2018-04-07 21:55:15 -05:00
def available_years
2018-04-05 17:03:34 -05:00
# i know this is long, ill fix it later to generate the numbers or something
2018-04-07 21:55:15 -05:00
@year || = %w[
2018-04-05 17:03:34 -05:00
2002 2003 2004 2005 2006 2007
2008 2009 2010 2011 2012 2013
2014 2015 2016 2017 2018 ]
end
2018-04-07 21:55:15 -05:00
def xml_feed_url
endpoint = 'xml/cve/2.0/'
url = self . base_uri + endpoint
uri = URI ( url )
2018-04-07 07:36:17 -05:00
end
2018-04-07 21:55:15 -05:00
def xml_file ( year )
xml_file = " nvdcve-2.0- #{ year } .xml.gz "
end
2018-04-05 17:03:34 -05:00
end
2018-04-07 21:55:15 -05:00
cve = CVE . new
request_url = " #{ cve . xml_feed_url } #{ cve . xml_file ( 2003 ) } "
` wget #{ request_url } `