Skip to main content

Network Calculator

The What and Why of Network Calculations

In networking, IP addresses and subnet masks are crucial for defining the structure and reach of the network. However, doing these calculations manually can be cumbersome and error-prone. This is where Python, with its vast library support and simplicity, can be a lifesaver.

In this article, we'll delve into a Python class called I have created called the 'NetworkCalculator'. It is designed to automate common network calculation tasks. To fully understand this, it is recommended you have some basic knowledge of IP addresses, subnet masks, network IDs, broadcast IDs, and CIDR notation. There are a tone of online resources to help your understanding. 

The NetworkCalculator class is initialized with an IP address in CIDR notation as input. CIDR (Classless Inter-Domain Routing) notation represents an IP address and its associated routing prefix. 

For instance, '192.168.1.10/24' is an example of an IP address in CIDR notation. The init method splits the IP address and the CIDR subnet prefix, and an IPv4Network object is created with these. The strict=False parameter allows the IP address part to be any IP address inside the network.

Network Calculator Methods you can use in your code


After creating the NetworkCalculator object, Here are several methods can we create and us to perform network calculations:

get_subnet_mask(): Returns the subnet mask of the network. The subnet mask defines the size of the network.

get_network_id(): Returns the Network ID. This is the first IP address in the network and it identifies the network itself.

get_next_network(): Returns the Network ID of the next network. It's calculated by adding 2^(32 - CIDR) to the network address.

get_broadcast_id(): Returns the last IP address in the network, which is used for broadcasting messages to all devices in the network.

get_first_ip(): Returns the first usable IP address in the network. It's simply the Network ID plus one.

get_last_ip(): Returns the last usable IP address in the network, which is one less than the broadcast ID.

get_total_ips(): Returns the total number of usable IP addresses in the network.

Installation

pip install networkcalculator

how to use the code

from cidr.network_calculator  import Network_Calculator

# Use it like this:
ip_list = ['198.51.100.0/22 ', '192.168.1.10/26', '172.16.0.5/16']

# Call the function with the list of CIDR IP addresses
Network_Calculator.print_network_info(ip_list)

# Call the function with the list of CIDR IP addresses and the filename of your output file
Network_Calculator.write_to_csv(ip_list, 'network.csv')

Output

CIDR Subnet Mask Network ID Next Network Broadcast ID First IP Last IP Total IPs
198.51.100.0/22 255.255.252.0 198.51.100.0 198.51.104.0 198.51.103.255 198.51.100.1 198.51.103.254 1022
192.168.1.10/26 255.255.255.192 192.168.1.0 192.168.1.64 192.168.1.63 192.168.1.1 192.168.1.62 62
172.16.0.5/16 255.255.0.0 172.16.0.0 172.17.0.0 172.16.255.255 172.16.0.1 172.16.255.254 65534

Bandwidth Calculator

In an era where data is being transferred in vast amounts and at high speeds, understanding bandwidth needs and capacity is an essential aspect of network management and application performance. A Bandwidth Calculator is a tool that helps you estimate the bandwidth needed to move a specific amount of data within a specific timeframe. In this article, we will delve into a Python code that creates a Bandwidth Calculator, designed to help you predict your bandwidth needs accurately.

The Bandwidth Calculator we are focusing on takes in four parameters: the throughput, the read percentage, the write percentage, and the initial data size. The Bandwidth Calculator is instantiated from the Bandwidth_Calculator class from the feeds.bandwidth_calculator module

from feeds.bandwidth_calculator import Bandwidth_Calculator

# Create a BandwidthCalculator object

bc = Bandwidth_Calculator('1 Gbps', 50, 50, '1 TB') # Throughput , reads %, writes /%, Initial data size 

# Write the results to a CSV file
bc.write_to_csv('feeds.csv')

Output

Media Throughput Read/Write Ratio Initial Data Size Disk Space Required (Read) Disk Space Required (Write) Bandwidth Required (Read) Bandwidth Required (Write) Transfer Time
1.0 Gbps 50:50 1.0 TB 62.5 MBps 62.5 MBps 500.0 Mbps 500.0 Mbps 2 hours 13 minutes 20.0 seconds seconds

About: 

Ray Bernard is a seasoned technologist specializing in cloud-based platforms, data science, and AI. He co-founded SuprFanz, a revolutionary cloud-based marketing company, and has held key roles at EMC, Dell, and Compaq/Dec. As an Affiliate Developer at Ticketmast, Systems Engineer, and Community Advocate, he demonstrated exceptional technical prowess and innovative thinking. Ray also taught Internet/Intranet Management & Design at Columbia University, further contributing to the field. With his vast experience and proactive problem-solving approach, he consistently drives digital transformation. 

Contact him: ray.bernard@outlook.com  LinkedIn : https://www.linkedin.com/in/ray-bernard-960382/ Git : https://github.com/raymondbernard/ MIT License

Copyright (c) 2023 Raymond Bernard

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for networkcalculator 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for networkcalculator 1.0.5
File Size Uploaded Provenance
networkcalculator-1.0.5.tar.gz 12.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for networkcalculator 1.0.5
File Interpreter ABI Platform
networkcalculator-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 24.9 kB

Release files / networkcalculator-1.0.5.tar.gz

Download URL networkcalculator-1.0.5.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
22625483f2a7b9d2310bcbcae9fe7871d7520ce4830e98631e830afe3d628e79
BLAKE2b-256 checksum
How to use checksums
5ae825fd2d7c8f12935cadb16a7c3695e2bdc3edf851f198f3a1d0812acea693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / networkcalculator-1.0.5-py3-none-any.whl

Download URL networkcalculator-1.0.5-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a7069b6a196cd2ee52bab8491cd2288950c0d6b1c66cc7ad434eeba7e99283a
BLAKE2b-256 checksum
How to use checksums
01a8e3464442988928dabef48fab23fcb486ccb3436bff8b184508fa236ac7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for networkcalculator 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page