Make sure that you have python's requests
module installed
$ pip3 install requests
If no arguments are specified, the script will not run. The last order of evaluation is checking to see if the --fileName argument has been set/
The logic is such that it follows this order:
- If no arguments are supplied, exit script.
- If one of the --all* arguments are supplied, check to see if the API Key exists (either checking the file prisma-access-api.key file or looking at the argument supplied from --apiKey.
- No API key, exit script.
- API key exists, then attempt to get the egress IPs based based on argument supplied.
- If egress IPs are returned from the API, then display them in tabulated format to stdout. Exit script.
- If egress IPs are returned from the API, and the
--outputJsonFile
or--outputCsvFile
or--outputEdlFile
argument is specified, then send the resulting output to those files in the appropriate format. Exit script. - For these 2 options below, the API key does not need to be set.
- If the
--fileName
argument is used, then display the output to stdout in tabulated format. - If the
--fileName
arguement and the--outputCsvFile
arguments are used in tandem, then the json formatted file is converted to comma separated values.
usage: format-egress-ips.py [-h] [--fileName FILENAME] [--setAPIKey SETAPIKEY] [--showAPIKey] [--deleteAPIKey] [--apiKey APIKEY]
[--environment ENVIRONMENT] [--allEgressIPs] [--allAROnboardedMobileUserLocations]
[--allActiveIPOnboardedMobileUserLocations] [--allActiveMobileUserAddresses] [--allRemoteNetworkAddresses]
[--allCleanPipeAddresses] [--allExplicitProxyAddresses] [--allLoopbackIPAddresses] [--outputJsonFile OUTPUTJSONFILE]
[--outputCsvFile OUTPUTCSVFILE] [--outputEdlFile OUTPUTEDLFILE]
Format Egress IPs 0.13
options:
-h, --help show this help message and exit
--fileName FILENAME List of json formatted egress IPs to convert.
--setAPIKey SETAPIKEY
Sets the API key into prisma-access-api.key file
--showAPIKey Shows the Prisma Access API Key from the prisma-access-api.key file.
--deleteAPIKey Deletes the Prisma Access API Key from prisma-access-api.key file.
--apiKey APIKEY Use stdin to enter API Key
--environment ENVIRONMENT
By default, script queries prod environment.
--allEgressIPs Shows all egress IPs for Prisma Access Service
--allAROnboardedMobileUserLocations
Retrieve all the active/reserved IP addresses for Mobile User Locations
--allActiveIPOnboardedMobileUserLocations
Retrieve all the active Mobile Users IP addresses
--allActiveMobileUserAddresses
Shows all Active Mobile User Addresses
--allRemoteNetworkAddresses
Shows all Remote Network Addresses
--allCleanPipeAddresses
Shows all Clean Pipe Addresses
--allExplicitProxyAddresses
Shows all Clean Pipe Addresses
--allLoopbackIPAddresses
Retrieves all the loopback addresses for each location.
--outputJsonFile OUTPUTJSONFILE
Send json output to file.
--outputCsvFile OUTPUTCSVFILE
Convert json output into comma separated values file.
--outputEdlFile OUTPUTEDLFILE
Convert json into external dynamic list file.
- To get the API key:
Creates the file prisma-access-api.key and adds the API key into it.
$ python3 format-egress-ips.py --setAPIKey this_is_my_api_key
Success
$
$ python3 format-egress-ips.py --showAPIKey
this_is_my_api_key
$ python3 format-egress-ips.py --deleteAPIKey
Success
$
First make sure API key is set (see above)
Use the --allEgressIPs
command.
$ python3 format-egress-ips.py --allEgressIPs
Location serviceType egress IP Active/Reserved
Singapore gp_gateway 123.234.123.124 active
Thailand gp_gateway 119.256.139.101 active
Vietnam gp_gateway 191.199.280.100 active
US Central gp_gateway 103.191.878.100 active
If you want to leverage the --apiKey
argument instead of using the options above, repeat the same command with --apiKey
defined.
$ python3 format-egress-ips.py --apiKey aldkfjlaksji4u50198u09uef-a9udfb9ausdf --allEgressIPs
Location serviceType egress IP Active/Reserved
Singapore gp_gateway 123.234.123.124 active
Thailand gp_gateway 119.256.139.101 active
Vietnam gp_gateway 191.199.280.100 active
US Central gp_gateway 103.191.878.100 active
This assumes you have the API key already set. Use the --apiKey
argument to pass the API key via stdin.
$ python3 format-egress-ips.py --allLoopbackIPAddresses
Type Location Loopback IP
gpcs_gp_portal US West 10.91.0.12
gpcs_gp_portal US East 10.91.0.7
gpcs_gp_gw US Southwest 10.91.0.13
gpcs_gp_gw US Central 10.91.0.4
gpcs_gp_gw US East 10.91.0.8
gpcs_gp_gw US Southeast 10.91.0.3
gpcs_gp_gw US Northwest 10.91.0.6
No output is displayed, but a file is created based on the argument supplied through --outputCsvFile
$ python3 format-egress-ips.py --allEgressIPs --outputCsvFile output.csv
Similarly as above, if you haven't defined an API key by using the --setAPIKey
, you can use the --apiKey
argument and pass it via stdin:
$ python3 format-egress-ips.py --apiKey aldkfjlaksji4u50198u09uef-a9udfb9ausdf --allEgressIPs --outputCsvFile output.csv
$ python3 format-egress-ips.py --apiKey aldkfjlaksji4u50198u09uef-a9udfb9ausdf --allEgressIPs --outputEdlFile output.edl
$ python3 format-egress-ips.py --fileName egress-ips.json
Example output:
Location serviceType egress IP Active/Reserved
Singapore gp_gateway 123.234.123.124 active
Thailand gp_gateway 119.256.139.101 active
Vietnam gp_gateway 191.199.280.100 active
US Central gp_gateway 103.191.878.100 active
$ python3 format-egress-ips.py --fileName egress-ips.json --outputCsvFile output.csv