<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AD Automaization script or API in Firewall and Security Management</title>
    <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260138#M61461</link>
    <description>&lt;P&gt;Here is what AI gave as far as Python scrip.&lt;/P&gt;
&lt;P&gt;import json&lt;BR /&gt;import requests&lt;BR /&gt;import ssl&lt;BR /&gt;import ldap3&lt;BR /&gt;from ldap3 import Server, Connection, ALL, NTLM&lt;/P&gt;
&lt;P&gt;# ---- CONFIG ----&lt;BR /&gt;CP_API_URL = "https://&amp;lt;mgmt-server&amp;gt;/web_api"&lt;BR /&gt;CP_USERNAME = "api-admin"&lt;BR /&gt;CP_PASSWORD = "yourpassword"&lt;/P&gt;
&lt;P&gt;AD_SERVER = "ad.domain.local"&lt;BR /&gt;AD_USER = "DOMAIN\\ad_query_user"&lt;BR /&gt;AD_PASSWORD = "yourpassword"&lt;BR /&gt;AD_GROUP = "CN=GroupName,OU=Groups,DC=domain,DC=local"&lt;/P&gt;
&lt;P&gt;FIREWALL_GROUP_NAME = "AD_Synced_Group"&lt;/P&gt;
&lt;P&gt;# Disable SSL warnings (only if using self-signed certs!)&lt;BR /&gt;requests.packages.urllib3.disable_warnings()&lt;/P&gt;
&lt;P&gt;# ---- HELPER FUNCTIONS ----&lt;/P&gt;
&lt;P&gt;def login_cp():&lt;BR /&gt;url = f"{CP_API_URL}/login"&lt;BR /&gt;payload = {"user": CP_USERNAME, "password": CP_PASSWORD}&lt;BR /&gt;r = requests.post(url, json=payload, verify=False)&lt;BR /&gt;r.raise_for_status()&lt;BR /&gt;return r.json()["sid"]&lt;/P&gt;
&lt;P&gt;def logout_cp(sid):&lt;BR /&gt;requests.post(f"{CP_API_URL}/logout", headers={"X-chkp-sid": sid}, verify=False)&lt;/P&gt;
&lt;P&gt;def get_ad_group_members():&lt;BR /&gt;server = Server(AD_SERVER, get_info=ALL)&lt;BR /&gt;conn = Connection(server, user=AD_USER, password=AD_PASSWORD, authentication=NTLM, auto_bind=True)&lt;/P&gt;
&lt;P&gt;conn.search(&lt;BR /&gt;search_base=AD_GROUP,&lt;BR /&gt;search_filter='(objectClass=group)',&lt;BR /&gt;attributes=['member']&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;members = []&lt;BR /&gt;for entry in conn.entries:&lt;BR /&gt;for member_dn in entry.member.values:&lt;BR /&gt;members.append(member_dn.split(",")[0].split("=")[1]) # Extract sAMAccountName or CN&lt;/P&gt;
&lt;P&gt;conn.unbind()&lt;BR /&gt;return members&lt;/P&gt;
&lt;P&gt;def create_or_update_cp_group(sid, group_name, members):&lt;BR /&gt;# Check if group exists&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/show-group", json={"name": group_name}, headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;if r.status_code == 200:&lt;BR /&gt;print(f"Group {group_name} exists. Updating members...")&lt;BR /&gt;group_uid = r.json().get("uid")&lt;BR /&gt;payload = {&lt;BR /&gt;"uid": group_uid,&lt;BR /&gt;"members": members&lt;BR /&gt;}&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/set-group", json=payload, headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;else:&lt;BR /&gt;print(f"Creating new group {group_name}...")&lt;BR /&gt;payload = {&lt;BR /&gt;"name": group_name,&lt;BR /&gt;"members": members&lt;BR /&gt;}&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/add-group", json=payload, headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;&lt;BR /&gt;r.raise_for_status()&lt;BR /&gt;return r.json()&lt;/P&gt;
&lt;P&gt;def publish_changes(sid):&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/publish", headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;r.raise_for_status()&lt;BR /&gt;print("Changes published.")&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;# ---- MAIN SCRIPT ----&lt;/P&gt;
&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;print("[*] Logging into Check Point...")&lt;BR /&gt;sid = login_cp()&lt;BR /&gt;&lt;BR /&gt;print("[*] Querying Active Directory...")&lt;BR /&gt;members = get_ad_group_members()&lt;BR /&gt;print(f"[*] Found {len(members)} AD members.")&lt;/P&gt;
&lt;P&gt;print("[*] Updating Check Point group...")&lt;BR /&gt;update = create_or_update_cp_group(sid, FIREWALL_GROUP_NAME, members)&lt;/P&gt;
&lt;P&gt;print("[*] Publishing policy changes...")&lt;BR /&gt;publish_changes(sid)&lt;/P&gt;
&lt;P&gt;print("[*] Logging out.")&lt;BR /&gt;logout_cp(sid)&lt;/P&gt;
&lt;P&gt;print("[✓] Done.")&lt;/P&gt;</description>
    <pubDate>Fri, 17 Oct 2025 08:24:43 GMT</pubDate>
    <dc:creator>the_rock</dc:creator>
    <dc:date>2025-10-17T08:24:43Z</dc:date>
    <item>
      <title>AD Automaization script or API</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260137#M61460</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am trying to do some sort of automatization and group updating in my rules. I KNOW that i can do that with IDENTITY AWARENESS and i already have it running, But I have a couple of PCs without it, but they are grouped in AD.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I need to update the Groups in my rule regarding those AD Groups, like Identity Awareness but without having an agent running.&amp;nbsp;&lt;BR /&gt;I believe it is doable through Python or the REST API. But i want to know if there is already something like that or i need to start from the base!!&lt;BR /&gt;&lt;BR /&gt;THNX&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2025 05:57:11 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260137#M61460</guid>
      <dc:creator>ShadowNif</dc:creator>
      <dc:date>2025-10-17T05:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: AD Automaization script or API</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260138#M61461</link>
      <description>&lt;P&gt;Here is what AI gave as far as Python scrip.&lt;/P&gt;
&lt;P&gt;import json&lt;BR /&gt;import requests&lt;BR /&gt;import ssl&lt;BR /&gt;import ldap3&lt;BR /&gt;from ldap3 import Server, Connection, ALL, NTLM&lt;/P&gt;
&lt;P&gt;# ---- CONFIG ----&lt;BR /&gt;CP_API_URL = "https://&amp;lt;mgmt-server&amp;gt;/web_api"&lt;BR /&gt;CP_USERNAME = "api-admin"&lt;BR /&gt;CP_PASSWORD = "yourpassword"&lt;/P&gt;
&lt;P&gt;AD_SERVER = "ad.domain.local"&lt;BR /&gt;AD_USER = "DOMAIN\\ad_query_user"&lt;BR /&gt;AD_PASSWORD = "yourpassword"&lt;BR /&gt;AD_GROUP = "CN=GroupName,OU=Groups,DC=domain,DC=local"&lt;/P&gt;
&lt;P&gt;FIREWALL_GROUP_NAME = "AD_Synced_Group"&lt;/P&gt;
&lt;P&gt;# Disable SSL warnings (only if using self-signed certs!)&lt;BR /&gt;requests.packages.urllib3.disable_warnings()&lt;/P&gt;
&lt;P&gt;# ---- HELPER FUNCTIONS ----&lt;/P&gt;
&lt;P&gt;def login_cp():&lt;BR /&gt;url = f"{CP_API_URL}/login"&lt;BR /&gt;payload = {"user": CP_USERNAME, "password": CP_PASSWORD}&lt;BR /&gt;r = requests.post(url, json=payload, verify=False)&lt;BR /&gt;r.raise_for_status()&lt;BR /&gt;return r.json()["sid"]&lt;/P&gt;
&lt;P&gt;def logout_cp(sid):&lt;BR /&gt;requests.post(f"{CP_API_URL}/logout", headers={"X-chkp-sid": sid}, verify=False)&lt;/P&gt;
&lt;P&gt;def get_ad_group_members():&lt;BR /&gt;server = Server(AD_SERVER, get_info=ALL)&lt;BR /&gt;conn = Connection(server, user=AD_USER, password=AD_PASSWORD, authentication=NTLM, auto_bind=True)&lt;/P&gt;
&lt;P&gt;conn.search(&lt;BR /&gt;search_base=AD_GROUP,&lt;BR /&gt;search_filter='(objectClass=group)',&lt;BR /&gt;attributes=['member']&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;members = []&lt;BR /&gt;for entry in conn.entries:&lt;BR /&gt;for member_dn in entry.member.values:&lt;BR /&gt;members.append(member_dn.split(",")[0].split("=")[1]) # Extract sAMAccountName or CN&lt;/P&gt;
&lt;P&gt;conn.unbind()&lt;BR /&gt;return members&lt;/P&gt;
&lt;P&gt;def create_or_update_cp_group(sid, group_name, members):&lt;BR /&gt;# Check if group exists&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/show-group", json={"name": group_name}, headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;if r.status_code == 200:&lt;BR /&gt;print(f"Group {group_name} exists. Updating members...")&lt;BR /&gt;group_uid = r.json().get("uid")&lt;BR /&gt;payload = {&lt;BR /&gt;"uid": group_uid,&lt;BR /&gt;"members": members&lt;BR /&gt;}&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/set-group", json=payload, headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;else:&lt;BR /&gt;print(f"Creating new group {group_name}...")&lt;BR /&gt;payload = {&lt;BR /&gt;"name": group_name,&lt;BR /&gt;"members": members&lt;BR /&gt;}&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/add-group", json=payload, headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;&lt;BR /&gt;r.raise_for_status()&lt;BR /&gt;return r.json()&lt;/P&gt;
&lt;P&gt;def publish_changes(sid):&lt;BR /&gt;r = requests.post(f"{CP_API_URL}/publish", headers={"X-chkp-sid": sid}, verify=False)&lt;BR /&gt;r.raise_for_status()&lt;BR /&gt;print("Changes published.")&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;# ---- MAIN SCRIPT ----&lt;/P&gt;
&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;print("[*] Logging into Check Point...")&lt;BR /&gt;sid = login_cp()&lt;BR /&gt;&lt;BR /&gt;print("[*] Querying Active Directory...")&lt;BR /&gt;members = get_ad_group_members()&lt;BR /&gt;print(f"[*] Found {len(members)} AD members.")&lt;/P&gt;
&lt;P&gt;print("[*] Updating Check Point group...")&lt;BR /&gt;update = create_or_update_cp_group(sid, FIREWALL_GROUP_NAME, members)&lt;/P&gt;
&lt;P&gt;print("[*] Publishing policy changes...")&lt;BR /&gt;publish_changes(sid)&lt;/P&gt;
&lt;P&gt;print("[*] Logging out.")&lt;BR /&gt;logout_cp(sid)&lt;/P&gt;
&lt;P&gt;print("[✓] Done.")&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2025 08:24:43 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260138#M61461</guid>
      <dc:creator>the_rock</dc:creator>
      <dc:date>2025-10-17T08:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: AD Automaization script or API</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260207#M61462</link>
      <description>&lt;P&gt;In case you've not seen, we have an Identity Awareness API:&amp;nbsp;&lt;A href="https://sc1.checkpoint.com/documents/latest/IdentityAPIs/#ida_api_intro~v1%20" target="_blank"&gt;https://sc1.checkpoint.com/documents/latest/IdentityAPIs/#ida_api_intro~v1%20&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;The script&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/38213"&gt;@the_rock&lt;/a&gt;&amp;nbsp;provided is completely wrong as it's calling the wrong API for this.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2025 20:54:04 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260207#M61462</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2025-10-17T20:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: AD Automaization script or API</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260209#M61463</link>
      <description>&lt;P&gt;I blame AI lol&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2025 20:58:56 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/AD-Automaization-script-or-API/m-p/260209#M61463</guid>
      <dc:creator>the_rock</dc:creator>
      <dc:date>2025-10-17T20:58:56Z</dc:date>
    </item>
  </channel>
</rss>

