Coder Social home page Coder Social logo

israel-lugo / netcalc Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 0.0 79 KB

Advanced network calculator and address planning helper

License: GNU General Public License v3.0

Python 100.00%
address-planning calculator ipv4 ipv6 netcalc network network-admin network-management prefixes

netcalc's People

Contributors

israel-lugo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

netcalc's Issues

Hierarchical splits

It would be nice to have the ability to split prefixes hierarchically, i.e.:

$ ./netcalc.py split 10.64.0.0/10 13 15

This would print a tree, splitting first with /13, then /14, then /15, with nested indentation, similarly to the tree command.

New command for static information

Create a new command to provide static information on a subnet, e.g. netmask, bitmask, start and end IP, and so on.

The kind of thing that e.g. ipcalc or sipcalc provide, but we might as well provide it as well so people can use a single tool.

Autodetect IP addresses from a routing table output

The add-file command reads network addresses from files. Right now, it only supports clean lists of addresses, e.g.:

10.0.0.0/24
192.0.2.0/27
10.5.7.128/25

It would be nice, however, to be able to feed add-file directly with the output of a "show route" command from some router, e.g.:

B        10.20.0.0/15 [20/40000] via 198.51.100.134, 3d14h
O        10.34.1.0/24 [110/200] via 198.51.100.142, 7w0d, Vlan0021
O E2     10.35.0.0/16 [110/20] via 198.51.100.142, 7w0d, Vlan0021
B        10.98.0.0/14 [20/40000] via 198.51.100.134, 3d14h
O E2     10.76.0.0/14 [110/20] via 198.51.100.70, 1w0d, Vlan0017
O E2     10.84.0.0/16 [110/20] via 198.51.100.38, 7w0d, Vlan0017
O E2     10.85.0.0/16 [110/20] via 198.51.100.49, 00:44:15, Vlan0013

Of course, we'd need to support any kind of format:

10.0.0.0/8         unreachable [sink_private 18:49:35] * (1)
10.16.64.0/24      via 198.51.100.129 on eth0 [igp_backbone 2016-11-16] * E1 (150/20) [198.51.100.5]
10.68.16.0/24      via 198.51.100.139 on eth0 [igp_backbone 2016-11-14] * IA (150/20) [198.51.100.139]
10.64.1.0/24       via 198.51.100.129 on eth1 [isp1 10:26:59] * (100) [AS65302?]
10.1.0.0/16        via 198.51.100.136 on eth0 [igp_backbone 2016-11-14] * IA (150/20) [198.51.100.136]

These can be dealt with simply by looking for the first thing in the line that looks like an address. Implementation can be either with a regexp (nightmare for IPv6) or by splitting the line into tokens and checking with netaddr.valid_ipv4 and netaddr.valid_ipv6.

The problem comes when we have output like this:

10.5.110.0/23      *[OSPF/10] 2d 01:03:59, metric 20
                    > to 198.51.100.130 via irb.2
10.0.0.0/23        *[OSPF/10] 2d 01:03:59, metric 20
                    > to 198.51.100.141 via irb.2
10.8.123.0/24      *[OSPF/10] 17:01:09, metric 20
                    > to 198.51.100.130 via irb.2
                      to 198.51.100.143 via irb.2
10.8.32.0/24       *[OSPF/10] 2d 01:03:59, metric 20
                    > to 198.51.100.139 via irb.2
10.20.0.0/15       *[OSPF/150] 00:53:42, metric 40000, tag 6666
                    > to 198.51.100.158 via irb.2
10.20.8.0/24       *[OSPF/150] 2d 01:03:59, metric 20, tag 0
                    > to 198.51.100.151 via irb.2

Some of these lines are interesting, some aren't. The problem is some lines have IP addresses that we don't care about (e.g. nexthops). For this kind of output, we'd need to be configurable somehow. Have some kind of way for the user to tell us "ignore stuff that looks like an IP address if it's on a line like this".

For now we'll just let the user worry about filtering invalid lines. They can use grep or similar and only give us what they want.

Accept network arguments from file

New option to specify networks from file. Ideally, this should work with a consistent syntax for all commands. One idea would be to have to have a global option that tells netcalc to read args from the file. Something like:

$ netcalc --arg-file networks.txt add

Where networks.txt is a list of networks, one per line:

198.18.0.0/24
198.18.1.0/24
10.1/16
10/16

Or, for the expr command, which has a more complex syntax:

$ netcalc --arg-file expr.txt expr

Where expr.txt contains:

2001:db8::/34
-
2001:db8::/38
+
2001:db8:100::/41

Read networks from file in different formats

We've had user requests to be able to read networks from various formats. Popular IPAM tools, CSV, SQL, and so on.

Not quite sure how we'd do on the interface side... Especially with regards to SQL, we need to have some way for the user to define the schema for us to retrieve it. But this needs addressing. CSV is probably the easiest to start with.

expr command should deal with missing whitespace around operators

It should be possible for the user to not use whitespace around the operators in the expr command. Right now, this is a syntax error:

$ ./netcalc.py expr 192.0.2.0/24 -192.0.2.0/25
usage: netcalc.py [-h] COMMAND ...
netcalc.py: error: unrecognized arguments: -192.0.2.0/25

This relates to the simple way in which we're parsing the command line. We'll need to be smarter than this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.