Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / tools / generate-bacnet-vendors.py
blob06d21e889277ee98933c798cb3860350a9d9b070
1 #!/usr/bin/env python3
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
7 # SPDX-License-Identifier: GPL-2.0-or-later
8 '''Update the BACNET vendors list.
10 generate-bacnet-vendors generates output containing BACNET vendor Identifiers.
12 Copyright 2023 Jaap Keuter <jaap.keuter@xs4all.nl>
13 based on work by Anish Bhatt <anish@chelsio.com>
15 '''
17 import sys
18 import urllib.request, urllib.error, urllib.parse
19 from bs4 import BeautifulSoup
21 def exit_msg(msg=None, status=1):
22 if msg is not None:
23 sys.stderr.write(msg + '\n\n')
24 sys.stderr.write(__doc__ + '\n')
25 sys.exit(status)
27 req_headers = { 'User-Agent': 'Wireshark generate-bacnet-vendors' }
28 try:
29 req = urllib.request.Request("https://bacnet.org/assigned-vendor-ids/", headers=req_headers)
30 response = urllib.request.urlopen(req)
31 lines = response.read().decode()
32 response.close()
33 except urllib.error.HTTPError as err:
34 exit_msg("HTTP error fetching {0}: {1}".format(url, err.reason))
35 except urllib.error.URLError as err:
36 exit_msg("URL error fetching {0}: {1}".format(url, err.reason))
37 except OSError as err:
38 exit_msg("OS error fetching {0}".format(url, err.strerror))
39 except Exception:
40 exit_msg("Unexpected error:", sys.exc_info()[0])
42 soup = BeautifulSoup(lines, "html.parser")
43 table = soup.find('table')
44 rows = table.findAll('tr')
46 entry = "static const value_string\nBACnetVendorIdentifiers [] = {"
48 for tr in rows:
49 cols = tr.findAll('td')
50 for index,td in enumerate(cols[0:2]):
51 text = ''.join(td.find(string=True))
52 if index == 0:
53 entry = " { %4s" % text
54 else:
55 entry += ", \"%s\" }," % text.rstrip()
56 print(entry)
58 entry = " { 0, NULL }\n};"
59 print(entry)