Last active
August 22, 2020 14:40
-
-
Save benjaminlaird/01854d8d7f6a9702b5c4997957d81ba8 to your computer and use it in GitHub Desktop.
Create all network prefixes for a given CIDR to join against IPs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark.sql.functions import udf, explode | |
from pyspark.sql.types import ArrayType, StringType | |
def get_networks(low, high): | |
return [str(ipaddress.ip_address(x)) | |
for x in range(int(ipaddress.ip_address(low)), | |
int(ipaddress.ip_address(high)), 256)] | |
get_networks_udf = udf(get_networks, ArrayType(StringType())) | |
asns.select(explode(get_networks_udf(asns.ip_min, asns.ip_max))).show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample: