Package: cirdhighspeedcoverter
High speed conversion of IP addresses represented in CIDR notation into their corresponding start and end IPs, along with their respective subnet masks.Tested against Windows 10 / Python 3.10 / Anacondapip install cirdhighspeedcoverterThe cidr_to_ip_and_subnet_mask function serves as a versatile tool for converting
IP addresses represented in CIDR (Classless Inter-Domain Routing) notation into
their corresponding start and end IPs, along with their respective subnet masks.
This process is crucial in network management and data analysis tasks.
By automating this conversion, the function significantly accelerates the handling of
large datasets containing CIDR notation IP addresses. It accepts various input formats,
including lists, pandas Series, and DataFrames, enhancing its adaptability.
Leveraging optimized array operations through NumPy and numexpr,
the function ensures efficient processing, particularly with extensive datasets.
This functionality is valuable to network administrators, data scientists, security
professionals, and developers alike, providing a streamlined approach for tasks
involving IP address manipulation and analysis. Ultimately, it simplifies the management
of network configurations and enhances the efficiency of data processing pipelines
that involve IP address transformations.Advantages:Automation and Efficiency:It automates the process of converting CIDR notation IP addresses to start and
end IP addresses along with subnet masks. This can save a significant
amount of time and effort compared to manual conversion.Scalability:It can handle a large number of CIDR notation IP addresses
efficiently, making it suitable for processing datasets
with a large number of IP addresses.Flexibility:The function can accept input in various formats, including lists, pandas Series, and DataFrames.
This makes it versatile and adaptable to different data structures.Optimized Computation:The function leverages NumPy and numexpr for efficient array operations,
which can lead to improved performance, especially with large datasets.Readability and Reusability:The function is well-organized and includes meaningful variable names,
making it easy for others (and the original developer) to understand and reuse the code.fromcirdhighspeedcoverterimportcidr_to_ip_and_subnet_maskdf2=pd.read_csv(r"C:\Users\hansc\Downloads\GeoLite2-City-CSV_20230908\GeoLite2-City-CSV_20230908\GeoLite2-City-Blocks-IPv4.csv")print(df2[:10].to_string())df=cidr_to_ip_and_subnet_mask(df2[:1000].network.to_list())df=cidr_to_ip_and_subnet_mask(df2[:1000].network)df=cidr_to_ip_and_subnet_mask(df2[:1000],column="network")print(df[:10].to_string())networkgeoname_idregistered_country_geoname_idrepresented_country_geoname_idis_anonymous_proxyis_satellite_providerpostal_codelatitudelongitudeaccuracy_radius01.0.0.0/242077456.02077456.0NaN00NaN-33.4940143.21041000.011.0.1.0/241814991.01814991.0NaN00NaN34.7732113.72201000.021.0.2.0/231814991.01814991.0NaN00NaN34.7732113.72201000.031.0.4.0/222147714.02077456.0NaN002000-33.8715151.20061000.041.0.8.0/211814991.01814991.0NaN00NaN34.7732113.72201000.051.0.16.0/201861060.01861060.0NaN00NaN35.6897139.6895500.061.0.32.0/191814991.01814991.0NaN00NaN34.7732113.72201000.071.0.64.0/221862415.01861060.0NaN00730-085134.3927132.45015.081.0.68.0/2311818936.01861060.0NaN00739-042434.2976132.289820.091.0.70.0/251856520.01861060.0NaN00730-001134.3978132.452510.0aa_startipaa_subnetaa_startip_intaa_endipaa_endip_intaa_subnetmask01.0.0.024167772161.0.0.25516777471255.255.255.011.0.1.024167774721.0.1.25516777727255.255.255.021.0.2.023167777281.0.3.25516778239255.255.254.031.0.4.022167782401.0.7.25516779263255.255.252.041.0.8.021167792641.0.15.25516781311255.255.248.051.0.16.020167813121.0.31.25516785407255.255.240.061.0.32.019167854081.0.63.25516793599255.255.224.071.0.64.022167936001.0.67.25516794623255.255.252.081.0.68.023167946241.0.69.25516795135255.255.254.091.0.70.025167951361.0.70.12716795263255.255.255.128ConvertCIDRnotationIPaddressestostartandendIPaddressesalongwithsubnetmasks.ThisfunctiontakesalistorpandasDataFrame/SeriescontainingCIDRnotationIPaddressesandreturnsaDataFramewiththefollowingcolumns:-'aa_startip':ThestartingIPaddressinstringformat.-"aa_subnet":Thesubnetmaskinintegerformat(uint8).-'aa_endip':TheendingIPaddressinstringformat.-'aa_startip_int':ThestartingIPaddressinintegerformat(uint32).-'aa_endip_int':TheendingIPaddressinintegerformat(uint32).-'aa_subnetmask':Thesubnetmaskinstringformat.Parameters:-----------df_series_list:list,pandas.Series,orpandas.DataFrameTheinputdatacontainingCIDRnotationIPaddresses.column:str,optional(default="network")ThenameofthecolumncontainingtheCIDRnotationIPaddressesifdf_series_listisaDataFrame.Returns:--------pandas.DataFrameADataFramewiththeconvertedIPaddressesandsubnetmasks.