Skip to content

Commit

Permalink
Merge pull request #1 from Netnod/fix_issue_14
Browse files Browse the repository at this point in the history
Fixing issue tonyseek#14
  • Loading branch information
morphZ authored Dec 15, 2020
2 parents 96401ca + 30a6eaa commit ece99dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions openvpn_status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
RE_VIRTUAL_ADDR_MAC = re.compile(
u'^{0}:{0}:{0}:{0}:{0}:{0}$'.format(u'[a-f0-9]{2}'), re.I)
RE_VIRTUAL_ADDR_NETWORK = re.compile(u'/(\\d{1,3})$')
RE_VIRTUAL_ADDR_CLIENT = re.compile(u'C$')


def parse_time(time):
Expand All @@ -39,6 +40,10 @@ def parse_vaddr(virtual_addr):
if match and 0 < int(match.group(1)) <= 128:
return ipaddress.ip_network(virtual_addr)

match = RE_VIRTUAL_ADDR_CLIENT.search(virtual_addr)
if match:
return ipaddress.ip_address(RE_VIRTUAL_ADDR_CLIENT.sub('', virtual_addr))

return ipaddress.ip_address(virtual_addr)


Expand Down
3 changes: 3 additions & 0 deletions tests/data/openvpn-status.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Virtual Address,Common Name,Real Address,Last Ref
192.168.255.135,[email protected],10.10.10.10:49503,Thu Jun 18 08:12:09 2015
192.168.255.126,[email protected],10.10.10.10:64169,Thu Jun 18 08:11:55 2015
22:1d:63:bf:62:38,[email protected],10.0.0.100:55712,Thu Oct 19 20:14:19 2017
192.168.255.126C,[email protected],10.10.10.10:64169,Thu Jun 18 08:11:55 2015
192.168.255.16C,[email protected],10.10.10.10:64169,Thu Jun 18 08:11:55 2015
192.168.255.1C,[email protected],10.10.10.10:64169,Thu Jun 18 08:11:55 2015
GLOBAL STATS
Max bcast/mcast queue length,0
END
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_parser(openvpn_status):
status = parser.parse()

assert len(status.client_list) == 5
assert len(status.routing_table) == 7
assert len(status.routing_table) == 9

assert status.global_stats.max_bcast_mcast_queue_len == 0
assert status.updated_at == datetime.datetime(2015, 6, 18, 8, 12, 15)
Expand Down

0 comments on commit ece99dc

Please sign in to comment.