PHPackages                             futureweb/google-ip-prefix-diff-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. futureweb/google-ip-prefix-diff-php

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

futureweb/google-ip-prefix-diff-php
===================================

PHP implementation of Google's Python script for calculating Google Cloud IP range differences.

v2.0.0(1y ago)12MITPHPPHP &gt;=7.4

Since Nov 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/futureweb/google-ip-prefix-diff-php)[ Packagist](https://packagist.org/packages/futureweb/google-ip-prefix-diff-php)[ RSS](/packages/futureweb-google-ip-prefix-diff-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Google IP Prefix Difference PHP
===============================

[](#google-ip-prefix-difference-php)

[![License](https://camo.githubusercontent.com/db6b69f9886faa49567f7cf08c36333e6f55d807b3af2951fccba8a1fadea4ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6675747572657765622f676f6f676c652d69702d7072656669782d646966662d706870)](https://camo.githubusercontent.com/db6b69f9886faa49567f7cf08c36333e6f55d807b3af2951fccba8a1fadea4ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6675747572657765622f676f6f676c652d69702d7072656669782d646966662d706870)[![PHP Version](https://camo.githubusercontent.com/b43c9d6cd8939c4868f963284928566c4c35dd2da0725c027f95a3d62f2f0329/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c75652e737667)](https://camo.githubusercontent.com/b43c9d6cd8939c4868f963284928566c4c35dd2da0725c027f95a3d62f2f0329/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c75652e737667)

tl;dr
-----

[](#tldr)

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
--------

[](#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](https://cloud.google.com/vpc/docs/configure-private-google-access#ip-addr-defaults).

**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
--------

[](#features)

- **Fetches Google Cloud IP ranges** from official URLs:
    - [`goog.json`](https://www.gstatic.com/ipranges/goog.json): Complete list of Google IP ranges.
    - [`cloud.json`](https://www.gstatic.com/ipranges/cloud.json): External IP ranges for Google Cloud resources.
- **Compares the IP ranges** in `goog.json` and `cloud.json`.
- **Outputs the resulting CIDR ranges** used by Google APIs and services.

Version 2 Highlights
--------------------

[](#version-2-highlights)

- **IPv4 and IPv6 Support:** Handles both IPv4 and IPv6 prefixes, allowing for comprehensive IP range processing.
- **Efficient Range Processing:** Merges and sorts cloud IP ranges upfront to minimize redundancy and optimize subtraction operations.
- **Optimized Bitwise Operations:** Enhancements for both GMP and BCMath extensions to ensure fast and efficient bitwise computations.
- **Flexible Math Extensions:** Dynamically utilizes either the GMP or BCMath PHP extensions based on availability, preferring GMP for superior performance.
- **Easy Integration:** Designed to be included in other PHP projects seamlessly, preventing direct access for enhanced security.
- **Clear Documentation:** Comprehensive comments and documentation to facilitate easy understanding and maintenance.

Prerequisites
-------------

[](#prerequisites)

- **PHP 7.4 or higher**
- **PHP Extensions:**
    - **GMP** (preferred for optimal performance) **OR**
    - **BCMath**

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

---

How It Works
------------

[](#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

[](#why-this-is-important)

- These ranges are allocated dynamically and **change often**, so it's not possible to define static IP ranges for individual services or APIs.
- Google recommends **maintaining an up-to-date list** by automating this script to run daily or using alternatives like the `private.googleapis.com` VIP or Private Service Connect.

---

Installation via Composer
-------------------------

[](#installation-via-composer)

1. Clone this repository: ```
    composer require futureweb/google-ip-prefix-diff-php
    ```
2. Once installed, the script will be autoloaded by Composer, and you can use it in your project: ```
     google_ip_ranges.txt
    ```
2. Load the cached results in your executed scripts: ```
    $ip_ranges = file('google_ip_ranges.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    foreach ($ip_ranges as $cidr) {
        echo $cidr . PHP_EOL;
    }
    ```
3. 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
---------

[](#reference)

This is a PHP implementation of the Python script provided by Google: [Private Google Access IP Address Defaults](https://cloud.google.com/vpc/docs/configure-private-google-access#ip-addr-defaults)

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

540d ago

Major Versions

v1.0.1 → v2.0.02024-11-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/6149bfdfbff0e5711f1eb84f1ca8c1b4e218fdd4ec9ccd9274d8dd0d46fce685?d=identicon)[Futureweb](/maintainers/Futureweb)

---

Top Contributors

[![futureweb](https://avatars.githubusercontent.com/u/1698881?v=4)](https://github.com/futureweb "futureweb (25 commits)")

---

Tags

jsongooglecidrgoogle cloudip rangesofficial google IPs

### Embed Badge

![Health badge](/badges/futureweb-google-ip-prefix-diff-php/health.svg)

```
[![Health](https://phpackages.com/badges/futureweb-google-ip-prefix-diff-php/health.svg)](https://phpackages.com/packages/futureweb-google-ip-prefix-diff-php)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15267.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
