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>
18 import urllib
.request
, urllib
.error
, urllib
.parse
19 from bs4
import BeautifulSoup
21 def exit_msg(msg
=None, status
=1):
23 sys
.stderr
.write(msg
+ '\n\n')
24 sys
.stderr
.write(__doc__
+ '\n')
27 req_headers
= { 'User-Agent': 'Wireshark generate-bacnet-vendors' }
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()
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
))
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 [] = {"
49 cols
= tr
.findAll('td')
50 for index
,td
in enumerate(cols
[0:2]):
51 text
= ''.join(td
.find(string
=True))
53 entry
= " { %4s" % text
55 entry
+= ", \"%s\" }," % text
.rstrip()
58 entry
= " { 0, NULL }\n};"