Skip to content

Commit 6858291

Browse files
committed
added try block for better error handling
1 parent f1d345e commit 6858291

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

netmiko-interface-example/netmiko-get-interface.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,20 @@
4747
# Print the raw command output to the screen
4848
print(interface)
4949

50-
# Use regular expressions to parse the output for desired data
51-
name = re.search(r'interface (.*)', interface).group(1)
52-
description = re.search(r'description (.*)', interface).group(1)
53-
ip_info = re.search(r'ip address (.*) (.*)', interface)
54-
ip = ip_info.group(1)
55-
netmask = ip_info.group(2)
56-
57-
# Print the info to the screen
58-
print("The interface {name} has ip address {ip}/{mask}".format(
59-
name = name,
60-
ip = ip,
61-
mask = netmask,
50+
try:
51+
# Use regular expressions to parse the output for desired data
52+
name = re.search(r'interface (.*)', interface).group(1)
53+
description = re.search(r'description (.*)', interface).group(1)
54+
ip_info = re.search(r'ip address (.*) (.*)', interface)
55+
ip = ip_info.group(1)
56+
netmask = ip_info.group(2)
57+
58+
# Print the info to the screen
59+
print("The interface {name} has ip address {ip}/{mask}".format(
60+
name = name,
61+
ip = ip,
62+
mask = netmask,
63+
)
6264
)
63-
)
65+
except Exception:
66+
print("There was an error, Loopback103 might not exist.")

0 commit comments

Comments
 (0)