Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.

Commit fa8afe4

Browse files
committed
Add more address parsing examples
1 parent 7bc6374 commit fa8afe4

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

README.md

+25-14
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,35 @@ for ccp_obj in parse.find_objects('^interface'):
182182
intf_class = ccp_obj.interface_object.interface_class or ""
183183

184184
##########################################################################
185-
# Extract an IPv4Obj() with re_match_iter_typed()
185+
# Extract all IPv4Obj() with re_match_iter_typed()
186186
##########################################################################
187-
intf_dict = ccp_obj.re_match_iter_typed(
188-
r"ip\s+address\s+(?P<v4addr>\S.+)$",
189-
groupdict={"v4addr": IPv4Obj},
190-
default=None
191-
)
192-
intf_ipv4obj = intf_dict["v4addr"]
187+
for _obj in ccp_obj.children:
188+
# Get a dict() from re_match_iter_typed() by caling it with 'groupdict'
189+
intf_dict = _obj.re_match_iter_typed(
190+
# Add a regex match-group called 'v4addr'
191+
r"ip\s+address\s+(?P<v4addr>\S.+)$",
192+
# Cast the v4addr regex match group as an IPv4Obj() type
193+
groupdict={"v4addr": IPv4Obj},
194+
# Default to None if there is no regex match
195+
default=None
196+
)
197+
intf_ipv4obj = intf_dict["v4addr"]
193198

194199
##########################################################################
195-
# Extract an IPv6Obj() (only EUI-64 portion) with re_match_iter_typed()
200+
# Extract all IPv6Obj() with re_match_iter_typed()
196201
##########################################################################
197-
intf_dict = ccp_obj.re_match_iter_typed(
198-
r"ipv6\s+address\s+(?P<v6addr>\S.+)\s+(eui.64)$",
199-
groupdict={"v6addr": IPv6Obj},
200-
default=None
201-
)
202-
intf_ipv6obj = intf_dict["v6addr"]
202+
for _obj in ccp_obj.children:
203+
# Get a dict() from re_match_iter_typed() by caling it with 'groupdict'
204+
intf_dict = _obj.re_match_iter_typed(
205+
# Add regex match-groups called 'v6addr' and an optional 'ipv6type'
206+
r"ipv6\s+address\s+(?P<v6addr>\S.+)\s*(?P<v6type>eui.64|link.local)*$",
207+
# Cast the v6addr regex match group as an IPv6Obj() type
208+
groupdict={"v6addr": IPv6Obj, "v6type": str},
209+
# Default to None if there is no regex match
210+
default=None
211+
)
212+
intf_ipv6obj = intf_dict["v6addr"]
213+
intf_ipv6type = intf_dict["v6type"]
203214
```
204215

205216
When that is run, you will see information similar to this...

0 commit comments

Comments
 (0)