03CodiceCode
calcIP
Strumento in Python per subnetting e supernetting IPv4.
Python tool for IPv4 subnetting and supernetting.
PerchéWhy
Prima di configurare i router serve un piano di indirizzamento: dividere una rete in sottoreti, calcolare indirizzi di rete e di broadcast, contare gli host disponibili. A mano è lento ed è facile sbagliare, così ho scritto calcIP, uno strumento a riga di comando che fa questi calcoli al posto mio.
Before configuring routers you need an addressing plan: splitting a network into subnets, working out network and broadcast addresses, counting the available hosts. By hand it's slow and easy to get wrong, so I wrote calcIP, a command-line tool that does the maths for me.
Cosa calcolaWhat it computes
Dato un indirizzo IPv4 con la sua maschera in notazione CIDR, calcIP restituisce in decimale e in binario l'indirizzo di rete, il broadcast, la subnet mask e la wildcard, insieme al numero massimo di host; se la maschera è classful, indica anche la classe dell'indirizzo. Con una nuova maschera esegue il subnetting, se è più lunga, o il supernetting, se è più corta.
Given an IPv4 address and its CIDR mask, calcIP returns the network address, broadcast, subnet mask and wildcard in both decimal and binary, together with the maximum number of hosts; if the mask is classful, it also gives the address class. With a new mask it performs subnetting when the mask is longer, or supernetting when it is shorter.
Per esempio, bash calcip.sh -s 192.168.10.0/24 26 divide la rete 192.168.10.0/24 in sottoreti /26.
For example, bash calcip.sh -s 192.168.10.0/24 26 splits the 192.168.10.0/24 network into /26 subnets.
Come è fattoHow it's built
Il cuore è una classe IPv4 in Python che esegue le conversioni bit per bit; sopra c'è una piccola interfaccia a riga di comando, lanciata da uno script Bash con l'opzione -s per il subnetting e -S per il supernetting. Il progetto segue un approccio da ingegneria del software: c'è un documento dei requisiti (SRS) e ci sono test automatici scritti con unittest per verificare le conversioni.
At its core is a Python IPv4 class that does the conversions bit by bit; on top of it sits a small command-line interface, launched from a Bash script with -s for subnetting and -S for supernetting. The project follows a software engineering approach: there is a requirements document (SRS) and automated tests written with unittest to check the conversions.