allan icon

VPN Users Created After Date

allan | PRO | 12/25/23 09:52:05 PM UTC (Edited) | 0 ⭐ | 1953 👁️ | Never ⏰ | []
Python |

2.21 KB

|

Source Code

|

0 👍

/

0 👎

#!/usr/bin/env python3
 
# config.py with api_server, user_name, and password variables
import config
 
# https://github.com/CheckPointSW/cp_mgmt_api_python_sdk
import cpapi
import time
 
# search for VPN users created after this date
date_cutoff = "20200301"
 
# save account names to file
output_file = "output.csv"
 
 
query_parameters = {"command": "show-generic-objects",
                    "details_level": "full",
                    "payload": {
                        "class-name": "com.checkpoint.objects.classes.dummy.CpmiUser",
                        "limit": 50,
                        "offset": 0
                        }
                    }
 
 
cutoff = time.mktime(time.strptime(date_cutoff, "%Y%m%d"))
 
client_args = cpapi.APIClientArgs(server=config.api_server)
 
with open(output_file, "w") as f:
    f.write("\"login name\",\"create date\"\n")
 
    with cpapi.APIClient(client_args) as client:
        if client.check_fingerprint() is False:
            print("Server fingerprint does not match.")
            exit(1)
 
        login_response = client.login(config.user_name, config.password, read_only=True)
        if login_response.success is False:
            print("Server connection failed.")
            exit(2)
 
        keep_looping = True
        user_count = 0
 
        while keep_looping:
            query_result = client.gen_api_query(**query_parameters)
 
            page = query_result.__next__()
            if page.success and page.res_obj["data"]["total"] > 0:
 
                # start from the last user on this page
                query_parameters["payload"]["offset"] += len(page.data["objects"])
 
                for item in page.data["objects"]:
                    sec, msec = divmod(item["meta-info"]["creationTime"], 1000)
 
                    if sec > cutoff:
                        user_count += 1
 
                        f.write("\"{0}\",{1}\n".format(
                            item["name"], time.strftime("%m-%d-%Y", time.localtime(sec))
                        ))
            else:
                # api error or
                # exhausted all users in database
                keep_looping = False
        print("Total users: ", user_count)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎