<?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 Using API to update Permitted IP Addresses list in Panorama Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589639#M2383</link>
    <description>&lt;P&gt;We use the Permitted IP Addresses list (Panorama&amp;gt;Setup&amp;gt;Interfaces) to restrict access to Panorama to our public IPs. The problem we run into is that some of our devices use cellular as backup (new public IP every two days) or worse--Starlink (who change your public IP several times per day).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this list only uses IP, not DNS, I can't just use a dynamic DNS entries. My solution is to update the list manually every time I need to push a config. I'd like to use a script that makes API calls, but I can't find any documentation for the API calls that gets to anything in the Panorama&amp;gt;Setup area. Any idea where these commands might be hiding? Or is the API limited to only select commands? Maybe I need to just script accessing the CLI and editing it there, but I'm not sure I've seen those commands either...&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2024 18:38:48 GMT</pubDate>
    <dc:creator>JDBailey</dc:creator>
    <dc:date>2024-06-14T18:38:48Z</dc:date>
    <item>
      <title>Using API to update Permitted IP Addresses list</title>
      <link>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589639#M2383</link>
      <description>&lt;P&gt;We use the Permitted IP Addresses list (Panorama&amp;gt;Setup&amp;gt;Interfaces) to restrict access to Panorama to our public IPs. The problem we run into is that some of our devices use cellular as backup (new public IP every two days) or worse--Starlink (who change your public IP several times per day).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this list only uses IP, not DNS, I can't just use a dynamic DNS entries. My solution is to update the list manually every time I need to push a config. I'd like to use a script that makes API calls, but I can't find any documentation for the API calls that gets to anything in the Panorama&amp;gt;Setup area. Any idea where these commands might be hiding? Or is the API limited to only select commands? Maybe I need to just script accessing the CLI and editing it there, but I'm not sure I've seen those commands either...&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 18:38:48 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589639#M2383</guid>
      <dc:creator>JDBailey</dc:creator>
      <dc:date>2024-06-14T18:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using API to update Permitted IP Addresses list</title>
      <link>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589643#M2384</link>
      <description>&lt;P&gt;Hi &lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/285573"&gt;@JDBailey&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The XPath you are looking for is shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;/api/?type=config&amp;amp;action=get&amp;amp;xpath=/config/devices/entry[@name='localhost.localdomain']/deviceconfig/system/permitted-ip/entry[@name='172.16.0.0/12']&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That example adds 172.16.0.0/12 with no description to the Permitted IP Addresses of the Panorama management interface.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few ways to find an XML Path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Dig through the API browser.&amp;nbsp; &lt;A href="https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-panorama-api/get-started-with-the-pan-os-xml-api/explore-the-api/use-the-api-browser" target="_blank"&gt;https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-panorama-api/get-started-with-the-pan-os-xml-api/explore-the-api/use-the-api-browser&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Use the CLI.&amp;nbsp; &lt;A href="https://docs.paloaltonetworks.com/pan-os/10-1/pan-os-panorama-api/get-started-with-the-pan-os-xml-api/explore-the-api/use-the-cli-to-find-xml-api-syntax" target="_blank"&gt;https://docs.paloaltonetworks.com/pan-os/10-1/pan-os-panorama-api/get-started-with-the-pan-os-xml-api/explore-the-api/use-the-cli-to-find-xml-api-syntax&lt;/A&gt;&amp;nbsp; This one is very cool.&amp;nbsp; Remember that the API and CLI are very similar.&lt;/LI&gt;
&lt;LI&gt;If you have no idea where it is in the CLI, configure it in the GUI with a unique description and type 'show | match &amp;lt;unique-description&amp;gt;' in configuration mode.&amp;nbsp; Make sure to type 'set cli config-output-format set' in operational mode 1st.&lt;/LI&gt;
&lt;LI&gt;With practice, get used to the XML tree the same as you did CLI commands.&amp;nbsp; &lt;A href="https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-cli-quick-start/use-the-cli/load-configurations/load-a-partial-configuration/xpath-location-formats-determined-by-device-configuration" target="_blank"&gt;https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-cli-quick-start/use-the-cli/load-configurations/load-a-partial-configuration/xpath-location-formats-determined-by-device-configuration&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS The CLI command is 'set deviceconfig system permitted-ip 172.16.0.0/12'.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 21:30:16 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589643#M2384</guid>
      <dc:creator>TomYoung</dc:creator>
      <dc:date>2024-06-14T21:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using API to update Permitted IP Addresses list</title>
      <link>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589645#M2385</link>
      <description>&lt;P&gt;Thank you! I've been looking for this for years, but every time I start my search some network emergency pulled me away. I'll give it a test and if it works, I'll accept the solution. Wasn't expecting a reply this week, honestly. You've made my week!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 21:33:47 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/589645#M2385</guid>
      <dc:creator>JDBailey</dc:creator>
      <dc:date>2024-06-14T21:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using API to update Permitted IP Addresses list</title>
      <link>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/590113#M2388</link>
      <description>&lt;P&gt;TomYoung's advice helped me find exactly what I was looking for at this time as well as helping me see how to use the debugger to figure out x-path for other things I'm trying to do. I was surprised at how well ChatGPT did at writing clean Python code to do what I wanted. I just had to tweak my prompt a few times. The following prompt yielded the code below (I comment out the place where I fixed how to access a particular piece of data) that will retrieve the allowed IPs into a Python dict.&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;create a python script that will retrieve the xml data from panorama x-path /config/devices/entry[@name="localhost.localdomain"]/deviceconfig/system/permitted-ip using an api key for authentication and convert it to a dictionary keyed off of description&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests
import xml.etree.ElementTree as ET

############# Start Unique Vallues ###############
# Panorama API endpoint for retrieving permitted IPs
panorama_url = 'https://my.panarama.url/api/'

# API key for authentication
api_key = 'myApiKey'
#############  End Unique Vallues  ###############


# Parameters for the API request
params = {
    'type': 'config',
    'action': 'get',
    'key': api_key,
    'xpath': '/config/devices/entry[@name="localhost.localdomain"]/deviceconfig/system/permitted-ip'
}

def retrieve_xml_data():
    try:
        # Make the API request to Panorama
        response = requests.get(panorama_url, params=params, verify=False)  # Set verify=True to verify SSL certificates

        if response.status_code == 200:
            # Parse the XML response
            root = ET.fromstring(response.text)
            
            # Initialize dictionary to store permitted IPs keyed off of 'description'
            permitted_ips = {}

            # Iterate over &amp;lt;entry&amp;gt; elements under &amp;lt;address&amp;gt; to extract data
            for entry in root.findall('.//entry'):
                description = entry.find('description').text.strip()
                ip_address = entry.attrib["name"] # entry.find('address').text.strip()
                permitted_ips[description] = ip_address

            return permitted_ips

        else:
            print(f"Failed to retrieve XML data. Status code: {response.status_code}")
            return None

    except requests.exceptions.RequestException as e:
        print(f"An error occurred: {e}")
        return None

# Example usage:
if __name__ == "__main__":
    xml_data_dict = retrieve_xml_data()
    if xml_data_dict:
        print("Permitted IPs:")
        for description, ip_address in xml_data_dict.items():
            print(f"{description}: {ip_address}")
    else:
        print("Failed to retrieve XML data.")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 21 Jun 2024 20:08:58 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/590113#M2388</guid>
      <dc:creator>JDBailey</dc:creator>
      <dc:date>2024-06-21T20:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using API to update Permitted IP Addresses list</title>
      <link>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/590114#M2389</link>
      <description>&lt;P&gt;That rocks!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 20:12:42 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/panorama-discussions/using-api-to-update-permitted-ip-addresses-list/m-p/590114#M2389</guid>
      <dc:creator>TomYoung</dc:creator>
      <dc:date>2024-06-21T20:12:42Z</dc:date>
    </item>
  </channel>
</rss>

