Create a Post
Showing results for 
Search instead for 
Did you mean: 

Python group parser

I'm sharing a group parser I've coded in Python for specific use cases as it might be useful to some.

Written in Python v3.9.10 and R81+ API.

The code will parse groups and display the content of the group along with their value, for the most common data types found in network groups.

Default values are used as I use it now for smaller implementations, there might limitations in case of larger group count.

I'm using an API key to authenticate; it's not obfuscated in the code as it's the key of a home lab which gets scratched every now and then.

As it's for specific use the code is not especially optimized, I understand I could use more functions and the like.

If you consider the attached screenshots of the development environment, this is the output you get when running the code.



python .\
Logged in with session ID: SOmVlSQNG5xB6Pm7mTQkyCQTUzz1jlQs2uiSWr1aL7w user: api_user API version: 1.8

Number of global iterations: 6

Group name cpgroup-1
Starting general iteration 0
Group name: cpgroup-1
Number of items in group: 5
host, cphost-1 ,
network/mask length, net_10.20.10.0-24,, 24
range/ipv4-address-first/ipv4-address-last , range_cp_10.30.10.1- , ,
domain ,
group , cpgroup-2
End of listing for group cpgroup-1

Group name cpgroup-2
Starting general iteration 1
Group name: cpgroup-2
Number of items in group: 1
host, cphost-2 ,
End of listing for group cpgroup-2

Group name cpgroup-3
Starting general iteration 2
Group name: cpgroup-3
Number of items in group: 1
range/ipv4-address-first/ipv4-address-last , cprange_192.168.23.1-98 , ,
End of listing for group cpgroup-3

Group name cpgroup-4
Starting general iteration 3
Group name: cpgroup-4
Number of items in group: 1
network/mask length, cpnet_172.16.15.0-25,, 25
End of listing for group cpgroup-4

Group name cpgroup-5
Starting general iteration 4
Group name: cpgroup-5
Number of items in group: 2
host, cphost-100 ,
host, cphost-200 ,
End of listing for group cpgroup-5

Group name cpgroup-6
Starting general iteration 5
Group name: cpgroup-6
Number of items in group: 1
domain ,
End of listing for group cpgroup-6

Logout successful




3 Replies

Thanks for sharing. 👍

I suggest to move this to Scripts within our Toolbox category.

0 Kudos

Not everyone can post to Toolbox.
Adding @_Val_ 

0 Kudos

On it

0 Kudos