Skip to content

bigfunctions > ip_range2ip_networks

ip_range2ip_networks

Call or Deploy ip_range2ip_networks ?

✅ You can call this ip_range2ip_networks bigfunction directly from your Google Cloud Project (no install required).

  • This ip_range2ip_networks function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

ip_range2ip_networks(first_ip, last_ip)

Description

Convert an IP range into a json list of IP networks in CIDR notation (the list can have only one element)

Examples

select bigfunctions.eu.ip_range2ip_networks('1.0.0.0', '1.0.0.255')
select bigfunctions.us.ip_range2ip_networks('1.0.0.0', '1.0.0.255')
select bigfunctions.europe_west1.ip_range2ip_networks('1.0.0.0', '1.0.0.255')
+--------------+
| ip_networks  |
+--------------+
| [1.0.0.0/24] |
+--------------+

select bigfunctions.eu.ip_range2ip_networks('192.0.2.1', '192.0.2.15')
select bigfunctions.us.ip_range2ip_networks('192.0.2.1', '192.0.2.15')
select bigfunctions.europe_west1.ip_range2ip_networks('192.0.2.1', '192.0.2.15')
+----------------------------------------------------------+
| ip_networks                                              |
+----------------------------------------------------------+
| [192.0.2.1/32, 192.0.2.2/31, 192.0.2.4/30, 192.0.2.8/29] |
+----------------------------------------------------------+

Need help using ip_range2ip_networks?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using ip_range2ip_networks?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

A security analyst wants to identify all traffic originating from a specific range of IP addresses. They have logs containing source IP addresses and want to categorize these logs based on whether the source IP falls within a predefined range. The ip_range2ip_networks function can be used to convert the IP range into a list of CIDR blocks. This list can then be used in a WHERE clause with the IN operator or a JOIN operation to filter or categorize the log data efficiently.

Example Scenario:

The security analyst wants to flag all traffic from the IP range 192.168.1.100 to 192.168.1.110.

  1. Convert the IP range to CIDR notation using the function:
SELECT bigfunctions.us.ip_range2ip_networks('192.168.1.100', '192.168.1.110');

This will return:

+---------------------------------------------------------------------------------+
| ip_networks                                                                     |
+---------------------------------------------------------------------------------+
| [192.168.1.100/32, 192.168.1.102/31, 192.168.1.104/30, 192.168.1.108/30]       |
+---------------------------------------------------------------------------------+
  1. Use the result to filter the logs:

Let's assume the logs are stored in a table named traffic_logs with a column source_ip.

SELECT *
FROM traffic_logs
WHERE source_ip IN (
    SELECT ip
    FROM UNNEST(bigfunctions.us.ip_range2ip_networks('192.168.1.100', '192.168.1.110')) AS ip
);

This query effectively filters the traffic_logs table to only show entries where the source_ip falls within the specified IP range. This allows the analyst to easily isolate and analyze traffic from the range of interest.

This use case demonstrates how ip_range2ip_networks simplifies working with IP ranges in BigQuery by converting them into a more manageable and query-friendly CIDR representation. This is especially useful when dealing with large datasets and complex filtering requirements.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on