From 43a70dccc970b58f14d628469c6d0138d21f6e1f Mon Sep 17 00:00:00 2001 From: Kuba Marek Date: Fri, 29 Mar 2013 13:30:14 +0100 Subject: [PATCH] Attempt to fix exception with ipv6 addresses (issue #1). --- inhibit_shutdown.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/inhibit_shutdown.py b/inhibit_shutdown.py index ee17ec2..cb68213 100644 --- a/inhibit_shutdown.py +++ b/inhibit_shutdown.py @@ -29,8 +29,14 @@ def check_services(): if len(items) < 4: continue - local_addr, local_port = items[3].split(':') - remote_addr, remote_port = items[4].split(':') + local_addr, local_port = items[3].rsplit(':', maxsplit=1) + remote_addr, remote_port = items[4].rsplit(':', maxsplit=1) + + if local_addr[0] == '[' and local_addr[-1] == ']': + local_addr = local_addr[1:-1] + + if remote_addr[0] == '[' and remote_addr[-1] == ']': + remote_addr = remote_addr[1:-1] local_port = int(local_port)