blob: 930b3645668a1f1b1e44bf47ca194af1644a0a47 [file] [log] [blame]
Jason M. Billsd1e40602019-05-09 11:43:51 -07001#!/usr/bin/python3
Jason M. Billsd1e40602019-05-09 11:43:51 -07002import argparse
Patrick Williamsf6469e22022-12-04 15:22:14 -06003import re
4import sys
5
6import requests
Jason M. Billsd1e40602019-05-09 11:43:51 -07007from bs4 import BeautifulSoup
8
9
10def parse_args(argv):
11 """Parse the command-line arguments"""
Patrick Williamsf6469e22022-12-04 15:22:14 -060012 parser = argparse.ArgumentParser(description="Get the PCI-SIG Vendor IDs")
13 parser.add_argument(
14 "--http-proxy", action="store", help="HTTP Proxy Address"
15 )
16 parser.add_argument(
17 "--https-proxy", action="store", help="HTTPS Proxy Address"
18 )
Jason M. Billsd1e40602019-05-09 11:43:51 -070019 args = parser.parse_args(argv)
20 return args
21
22
23def main(argv):
24 """Go to the PCI-SIG members page and construct a
25 dictionary of member companies to their Vendor IDs"""
26 args = parse_args(argv)
27
Patrick Williamsf6469e22022-12-04 15:22:14 -060028 proxyDict = {"http": args.http_proxy, "https": args.https_proxy}
29 page = "https://pcisig.com/membership/member-companies"
Jason M. Billsd1e40602019-05-09 11:43:51 -070030 pciVendorIDs = {}
31 while True:
32 r = requests.get(page, proxies=proxyDict)
33 soup = BeautifulSoup(r.text)
34
35 for row in soup.table.tbody.find_all("tr"):
36 fields = row.find_all("td")
37 vendorID = fields[1].text.strip()
Patrick Williamsf6469e22022-12-04 15:22:14 -060038 if "hex" in vendorID.lower():
39 match = re.match(r"\w+ \((\w+) hex\)", vendorID, re.I)
Jason M. Billsd1e40602019-05-09 11:43:51 -070040 if match is not None:
41 vendorID = match.group(1)
42 else:
Patrick Williamsf6469e22022-12-04 15:22:14 -060043 vendorID = ""
44 if vendorID != "":
45 vendorName = fields[0].text.replace('"', "").strip()
Jason M. Billsd1e40602019-05-09 11:43:51 -070046 pciVendorIDs[vendorName] = vendorID
47
48 page = soup.find("a", title="Go to next page")
49 if page is None:
50 break
Patrick Williamsf6469e22022-12-04 15:22:14 -060051 page = "https://pcisig.com" + page["href"]
Jason M. Billsd1e40602019-05-09 11:43:51 -070052
53 for name, vid in sorted(pciVendorIDs.items(), key=lambda x: x[0].lower()):
Patrick Williamsf6469e22022-12-04 15:22:14 -060054 print('{{0x{}, "{}"}},'.format(vid, name))
Jason M. Billsd1e40602019-05-09 11:43:51 -070055
56
Patrick Williamsf6469e22022-12-04 15:22:14 -060057if __name__ == "__main__":
Jason M. Billsd1e40602019-05-09 11:43:51 -070058 main(sys.argv[1:])