-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathAddress.py
39 lines (30 loc) · 898 Bytes
/
Address.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash python
"""
This simple application takes a string form of a BACnet address from the
command line and attempts to interpret it.
"""
import sys
from bacpypes.consolelogging import ArgumentParser
from bacpypes.pdu import Address
# build a parser for the command line arguments
parser = ArgumentParser(description=__doc__)
parser.add_argument("address",
help="address to interpret",
)
# parse the command line arguments
args = parser.parse_args()
# try to interpret the address
try:
addr = Address(args.address)
except Exception as err:
print(err)
sys.exit(1)
# print the string form
print(addr)
# print the various components
for attr in [
'addrType', 'addrNet', 'addrAddr', 'addrLen', # universal
'addrTuple', 'addrBroadcastTuple', # IPv4
]:
if hasattr(addr, attr):
print("%s: %r" % (attr, getattr(addr, attr)))