Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Alex-
Advisor
Advisor

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 .\group_matcher.py
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 , 10.10.10.10
network/mask length, net_10.20.10.0-24,10.20.10.0, 24
range/ipv4-address-first/ipv4-address-last , range_cp_10.30.10.1-10.30.10.72 , 10.30.10.1 , 10.30.10.72
domain , .community.checkpoint.com
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 , 10.20.20.20
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 , 192.168.23.1 , 192.168.23.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,172.16.15.0, 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 , 10.100.1.1
host, cphost-200 , 10.200.1.1
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 , .google.com
End of listing for group cpgroup-6

Logout successful

 

 

group1.pnggroup2.pnggroup3.pnggroup4.pnggroup5.pnggroup6.pnggrouplist.png

3 Replies
Danny
Champion Champion
Champion

Thanks for sharing. 👍

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

0 Kudos
PhoneBoy
Admin
Admin

Not everyone can post to Toolbox.
Adding @_Val_ 

0 Kudos
_Val_
Admin
Admin

On it

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events