Download the PHP package futureweb/google-ip-prefix-diff-php without Composer

On this page you can find all versions of the php package futureweb/google-ip-prefix-diff-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package google-ip-prefix-diff-php

Google IP Prefix Difference PHP

License PHP Version

tl;dr

This script outputs all IP ranges used by Google's own services, excluding IP ranges assigned to Google Cloud customers. It is useful for identifying the IPs utilized exclusively by Google's infrastructure.

Overview

Google IP Prefix Difference PHP is a robust and efficient PHP script designed to retrieve and process Google's IP prefixes. It calculates the difference between two sets of IP ranges provided by Google, specifically those present in goog.json but not in cloud.json.

The script determines the IP ranges used by the default domains for Google APIs and services, such as *.googleapis.com and *.gcr.io. These IP ranges are calculated by subtracting the ranges in cloud.json (external IP ranges for Google Cloud customer resources) from those in goog.json (the complete list of Google IP ranges available on the internet).

For more information, see the Google Documentation.

Version 2 of the script introduces comprehensive support for both IPv4 and IPv6 addresses, expanding its applicability and ensuring compatibility with modern network configurations.

Features

Version 2 Highlights

Prerequisites

Ensure that at least one of these extensions is enabled in your PHP environment.


How It Works

  1. The script fetches the JSON files from:
  2. It parses the JSON data and extracts the IPv4 prefixes.
  3. It calculates the difference between the IP ranges in goog.json and cloud.json, determining the IP ranges used by Google APIs and services.
  4. It outputs the resulting prefixes as an array of CIDRs.

Why This Is Important


Installation via Composer

  1. Clone this repository: bash <?php require 'vendor/autoload.php';

    // Use the functions defined in the script $ip_prefixes = get_google_ip_prefixes_difference();

    if ($ip_prefixes !== false) { // Output IPv4 prefixes foreach ($ip_prefixes['ipv4'] as $cidr) { echo $cidr . PHP_EOL; } // Output IPv6 prefixes foreach ($ip_prefixes['ipv6'] as $cidr) { echo $cidr . PHP_EOL; } } else { echo "Failed to retrieve IP prefixes." . PHP_EOL; }

Manual Installation

  1. Clone this repository: bash $ip_prefixes = include 'google_ip_prefix_diff.php';

    if ($ip_prefixes !== false) { // Output IPv4 prefixes foreach ($ip_prefixes['ipv4'] as $cidr) { echo $cidr . PHP_EOL; } // Output IPv6 prefixes foreach ($ip_prefixes['ipv6'] as $cidr) { echo $cidr . PHP_EOL; } } else { echo "Failed to retrieve IP prefixes." . PHP_EOL; }

Important Note: Avoid Direct Inclusion in Executed Scripts

This script downloads large JSON files and processes the differences in IP ranges, which can be time-consuming and resource-intensive. For this reason:

Suggested Basic Caching Logic

  1. Run the script periodically (e.g., hourly) to generate the CIDR ranges: bash $ip_ranges = file('google_ip_ranges.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    foreach ($ip_ranges as $cidr) { echo $cidr . PHP_EOL; }

  2. Automate the caching process using a cron job or similar scheduling tool:
    
    # Run the script daily at midnight to refresh the cache
    0 0 * * * /usr/bin/php /path/to/google_ip_prefix_diff.php > /path/to/cached_ip_ranges.txt

Reference

This is a PHP implementation of the Python script provided by Google: Private Google Access IP Address Defaults

License

This project is licensed under the MIT License. See the LICENSE file for details.


All versions of google-ip-prefix-diff-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package futureweb/google-ip-prefix-diff-php contains the following files

Loading the files please wait ...