# Convert IP Range into CIDR

```
import ipaddress

# Lista de intervalos de IP
ip_ranges = [
    "41.63.160.0-41.63.160.255",
    "41.63.161.0-41.63.161.255"
]

# Função para converter intervalo de IP para CIDR
def ip_range_to_cidr(ip_range):
    start, end = ip_range.split('-')
    start_ip = ipaddress.IPv4Address(start)
    end_ip = ipaddress.IPv4Address(end)
    subnet = ipaddress.summarize_address_range(start_ip, end_ip)
    return str(list(subnet)[0]) if subnet else None

# Converter intervalos para CIDR
cidr_ranges = [ip_range_to_cidr(ip_range) for ip_range in ip_ranges]

# Mostrar os resultados
for cidr in cidr_ranges:
    print(cidr)

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.seguranca-informatica.pt/resources-1/convert-ip-range-into-cidr.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
