Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 2 | import argparse |
Patrick Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 3 | import re |
| 4 | import sys |
| 5 | |
| 6 | import requests |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 7 | from bs4 import BeautifulSoup |
| 8 | |
| 9 | |
| 10 | def parse_args(argv): |
| 11 | """Parse the command-line arguments""" |
Patrick Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 12 | 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. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 19 | args = parser.parse_args(argv) |
| 20 | return args |
| 21 | |
| 22 | |
| 23 | def 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 Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 28 | proxyDict = {"http": args.http_proxy, "https": args.https_proxy} |
| 29 | page = "https://pcisig.com/membership/member-companies" |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 30 | 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 Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 38 | if "hex" in vendorID.lower(): |
| 39 | match = re.match(r"\w+ \((\w+) hex\)", vendorID, re.I) |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 40 | if match is not None: |
| 41 | vendorID = match.group(1) |
| 42 | else: |
Patrick Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 43 | vendorID = "" |
| 44 | if vendorID != "": |
| 45 | vendorName = fields[0].text.replace('"', "").strip() |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 46 | pciVendorIDs[vendorName] = vendorID |
| 47 | |
| 48 | page = soup.find("a", title="Go to next page") |
| 49 | if page is None: |
| 50 | break |
Patrick Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 51 | page = "https://pcisig.com" + page["href"] |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 52 | |
| 53 | for name, vid in sorted(pciVendorIDs.items(), key=lambda x: x[0].lower()): |
Patrick Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 54 | print('{{0x{}, "{}"}},'.format(vid, name)) |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 55 | |
| 56 | |
Patrick Williams | f6469e2 | 2022-12-04 15:22:14 -0600 | [diff] [blame] | 57 | if __name__ == "__main__": |
Jason M. Bills | d1e4060 | 2019-05-09 11:43:51 -0700 | [diff] [blame] | 58 | main(sys.argv[1:]) |