Metadata-Version: 2.4
Name: azure-json-ips
Version: 0.1.0
Summary: Resolve Azure IP CIDR ranges from Microsoft's published service tags JSON
Author: GetAzureIPs
Keywords: azure,json,ip,cidr,network
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: flask>=3.0.0

# azure-json-ips

Python library that resolves Azure-published IP ranges from Microsoft's service tags JSON source.

It fetches and parses service tags data, extracts IPv4 and IPv6 CIDRs, and can
optionally filter by region, system service, platform, or full tag name.

## Why JSON?

Azure publishes service tag metadata in a machine-readable JSON payload. It
contains top-level metadata and a `values` list with network definitions.

Each service tag entry includes fields such as:

- `name`
- `properties.region`
- `properties.systemService`
- `properties.platform`
- `properties.addressPrefixes`

The top-level payload includes:

- `changeNumber`
- `cloud`

This package reads that source directly.

## Install

### From PyPI

```bash
pip install azure-json-ips
```

### Local Development

From the project root:

```bash
pip install -e .
```

## Library Usage

```python
from azure_json_ips import AzureIPQuery, get_azure_ip_cidrs

result = get_azure_ip_cidrs()
query = AzureIPQuery.from_cidrs(result.cidrs)

print(result.change_number, result.cloud)
print(query.contains("20.36.0.0/14"))
print(query.collides("20.36.0.0-20.39.255.255"))
```

You can also filter the source data:

```python
result = get_azure_ip_cidrs(
    regions=("eastus",),
    system_services=("Storage",),
)
```

`result` is a `ResolutionResult` with:

- `cidrs`: sorted tuple of unique CIDR strings
- `change_number`: source change number from Azure
- `cloud`: source cloud identifier (for example `Public`)
- `source_url`: final JSON URL used
- `selected_prefix_count`: number of selected address prefixes before de-duplication

`AzureIPQuery` supports:

- `contains(value)`: full containment for IP, CIDR, or range string (`start-end`)
- `collides(value)`: any overlap for IP, CIDR, or range string (`start-end`)
- Specific methods: `contains_ip`, `contains_cidr`, `contains_range`, `collides_ip`, `collides_cidr`, `collides_range`

## Example Script

Run:

```bash
python examples/print_azure_ips.py
```

## Flask JSON Server Example

Run:

```bash
python examples/flask_server.py
```

All endpoints return JSON.

Examples:

```bash
curl "http://127.0.0.1:5003/health"
curl "http://127.0.0.1:5003/metadata"
curl "http://127.0.0.1:5003/cidrs"
curl "http://127.0.0.1:5003/networks"
curl "http://127.0.0.1:5003/check?value=20.36.0.0/14"
curl "http://127.0.0.1:5003/check?value=20.36.0.0-20.39.255.255"
curl "http://127.0.0.1:5003/check/range?start=20.36.0.0&end=20.39.255.255"
```
