Giter Club home page Giter Club logo

netcalc's Introduction

IP network calculator

License Badge GitHub Status Coverity Status

netcalc is a slimmed down clone of sipcalc, using the output format of ipcalc. It is written in C and only depends on a POSIX compliant C library. Both IPv4 and IPv6 are supported.

Image netcalc example run

Build & Install

Debian/Ubuntu

curl -sS https://deb.troglobit.com/pubkey.gpg | sudo tee /etc/apt/trusted.gpg.d/troglobit.asc
echo "deb [arch=amd64] https://deb.troglobit.com/debian stable main" | sudo tee /etc/apt/sources.list.d/troglobit.list
sudo apt-get update && sudo apt-get install netcalc

Docker

Automatically built images available here:

A Dockerfile is provided to simplify building and running netcalc.

docker build -t netcalc:latest .
docker run --rm netcalc:latest netcalc 172.16.10.10/16

Building from Source

First download the latest official release from GitHub:

Always use the versioned tarballs, they contain all required files to be able to build.

Configure & Build

The GNU Configure & Build system use /usr/local as the default install prefix. Here we override that to use /usr/, the netcalc binary will then be installed in /usr/bin:

$ ./configure --prefix=/usr
$ make -j5
$ sudo make install-strip

Building from GIT

If you want to contribute, or simply just try out the latest but unreleased features, then you need to know a few things about the [GNU build system][buildsystem]:

  • configure.ac and a per-directory Makefile.am are key files
  • configure and Makefile.in are generated from autogen.sh, they are not stored in GIT but automatically generated for the release tarballs
  • Makefile is generated by configure script

To build from GIT; clone the repository and run the autogen.sh script. This requires the GNU tools automake, autoconf and libtool to be installed on your system. Released tarballs do not require these tools.

$ sudo apt install git automake autoconf

Then you can clone the repository and create the configure script, which is not part of the GIT repo:

git clone https://github.com/troglobit/netcalc.git
cd netcalc/
./autogen.sh
./configure && make

GIT sources are a moving target and are not recommended for production systems, unless you know what you are doing!

Origin & References

The original sipcalc project was created by Simon Ekstrand in 2001. It is no longer actively maintained, but has a lot of features and is available on major Linux distributions and works on *BSD and Solaris.

Use GitHub to file bug reports, questions, feature requests or patches — preferably as pull requests.

netcalc's People

Contributors

abelbeck avatar barracuda156 avatar sbadia avatar sii avatar troglobit avatar vincentbernat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

netcalc's Issues

Add support for Cisco wildcard masks

Jerry Przybylski writes:

At our house, for our gig-fiber service, we use a Cisco 2921 router instead of a consumer-grade router. The documentation
of the Cisco IOS "standard" Access-Control statements uses xxx.xxx.xxx.xxx yyy.yyy.yyy.yyy syntax where x is the network,
and y is the COMPLEMENT of the usual netmask. A /24 network in an ACL would be 0.0.0.255 instead of 255.255.255.0

It would be nice, I think, for netcalc to support (output only, or output and input) this alternate (mask-complement)
net-mask syntax too.

I agree, this would be a neat thing to add to netcalc. Very neat and tidy first task for someone new to the project :)

For more information, e.g., see https://en.wikipedia.org/wiki/Wildcard_mask

pipe from stdin not working reliably

Piping from stdin is not working reliably. Sometimes works. Sometimes not...

netcalc 2601:186:4503:8130::1/64
works
echo 2601:186:4503:8130::1/64 | netcalc -
fails
echo fe80::20d:b9ff:fe41:7155/64 | netcalc -
works

when it fails... it does not output anything, just returns to command prompt.

Thanks
David

Add support for validating IPv4/IPV6 address

First, great tool ! We had a request for sipcalc for our project, but your adaptation seems perfect.

Is it time to make 2.0.1 official ?

A minor point, the automatic symlink creation of ipcalc is unwanted in our case, we use the Busybox flavor /bin/ipcalc in scripts, so we had to skip your Makefile target install to eliminate /usr/bin/ipcalc confusion.

A suggestion, add options to validate IPv4/IPv6 addresses ...

-c  Validate the IPv4 address, returns non-zero on invalid address, no output
-C  Validate the IPv6 address, returns non-zero on invalid address, no output

Thank your for netcalc.

Compile on macOS?

I would really like to compile netcalc on macOS, but fell on my face.

configure runs fine (no errors). But make spews out the following wall of text and then fails. Any possible clue or is this a dead end?

$ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in src
  CC       netcalc-netcalc.o
In file included from netcalc.c:40:
./netcalc.h:232:8: error: expected parameter declarator
size_t strlcpy(char *dst, const char *src, size_t siz);
       ^
/usr/include/secure/_string.h:108:47: note: expanded from macro 'strlcpy'
                __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                             ^
/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'
#    define _USE_FORTIFY_LEVEL 2
                               ^
In file included from netcalc.c:40:
./netcalc.h:232:8: error: expected ')'
/usr/include/secure/_string.h:108:47: note: expanded from macro 'strlcpy'
                __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                             ^
/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'
#    define _USE_FORTIFY_LEVEL 2
                               ^
./netcalc.h:232:8: note: to match this '('
/usr/include/secure/_string.h:108:47: note: expanded from macro 'strlcpy'
                __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:53: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                    ^
In file included from netcalc.c:40:
./netcalc.h:232:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
size_t strlcpy(char *dst, const char *src, size_t siz);
       ^
/usr/include/secure/_string.h:108:47: note: expanded from macro 'strlcpy'
                __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:31: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                              ^
In file included from netcalc.c:40:
./netcalc.h:232:8: error: conflicting types for '__builtin___strlcpy_chk'
/usr/include/secure/_string.h:108:3: note: expanded from macro 'strlcpy'
                __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                ^
./netcalc.h:232:8: note: '__builtin___strlcpy_chk' is a builtin with type 'unsigned long (char *, const char *, unsigned
      long, unsigned long)'
/usr/include/secure/_string.h:108:3: note: expanded from macro 'strlcpy'
                __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                ^
In file included from netcalc.c:40:
./netcalc.h:233:8: error: expected parameter declarator
size_t strlcat(char *dst, const char *src, size_t siz);
       ^
/usr/include/secure/_string.h:115:47: note: expanded from macro 'strlcat'
                __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                             ^
/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'
#    define _USE_FORTIFY_LEVEL 2
                               ^
In file included from netcalc.c:40:
./netcalc.h:233:8: error: expected ')'
/usr/include/secure/_string.h:115:47: note: expanded from macro 'strlcat'
                __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                             ^
/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'
#    define _USE_FORTIFY_LEVEL 2
                               ^
./netcalc.h:233:8: note: to match this '('
/usr/include/secure/_string.h:115:47: note: expanded from macro 'strlcat'
                __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:53: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                    ^
In file included from netcalc.c:40:
./netcalc.h:233:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
size_t strlcat(char *dst, const char *src, size_t siz);
       ^
/usr/include/secure/_string.h:115:47: note: expanded from macro 'strlcat'
                __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                                                            ^
/usr/include/secure/_common.h:39:31: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                              ^
In file included from netcalc.c:40:
./netcalc.h:233:8: error: conflicting types for '__builtin___strlcat_chk'
/usr/include/secure/_string.h:115:3: note: expanded from macro 'strlcat'
                __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                ^
./netcalc.h:233:8: note: '__builtin___strlcat_chk' is a builtin with type 'unsigned long (char *, const char *, unsigned
      long, unsigned long)'
/usr/include/secure/_string.h:115:3: note: expanded from macro 'strlcat'
                __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest))
                ^
2 warnings and 6 errors generated.
make[2]: *** [netcalc-netcalc.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

IPv6 address types are missing ULA

RFC 4193 specifies range of IPv6 for Unique Local Addressing unicast. Netcalc is not recognizing those, instead returning "Unassigned"

David

Need option to suppress all color coding in output

netcalc needs a way to output without any color coding. The control characters inserted before IPv6 addresses make it impossible to parse the strings output within another script (e.g. bash). So, for example, you cannot rely on substring:position because there are hidden control characters imbedded into the front of the ip address string.

Message error is missing

Tool doesn't return error if IP is invalid ( you can put any value, invalid values (zxvf:mlpr9:...) and the return is always 0, like if it was okay); if block 8 is suppressed it doesn't show ip address and it doesn't show any error (abff:0:ed4a:123f:ddd:3e4f:104f::);

Examples
#: netcalc zxvm:lçvd:: && echo Ok
#: Ok

#: netcalc 2fe1:d200:0:0:0:c801:a68:: 64
#: echo $?
#: 0

Add support for disabling ", Private network ..." from output

Jerry Przybylski writes:

A feature to suppress the output of "Reserved" IPs per RFC 1918 part 3 would be another nice feature.

I'm assuming you mean a way to disable the text after the comma in the output:

Hosts/Net: 254                   Class C, Private network (RFC1918)
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sure this could a be a pre-runtime flag to the configure script, or a command line option to netcalc itself. Also a very good task for a newcomer to the project :)

Add -R Min:Max "Range" option

Feature Request:

When configuring dnsmasq with a range of DHCP addresses (Min:Max) the calculation is quite simple when limiting your scope to only /24 networks. Currently we use some obfuscated bash code to generate the sequential decimal range Min:Max for an arbitrary network. A much better solution would be to use netcalc.

IPv4 options:
  -R Min:Max  Offset IPv4 network Range from Min to Max

Calculation:

RangeMin = (HostMin - 1) + Min

RangeMax = (HostMin - 1) + Max

Conditions: Min > 0 && Min < Max && Max < Hosts/Net

Examples:

netcalc -R 100:200 10.10.10.1/24
...
HostMin  : 10.10.10.1           00001010.00001010.00001010. 00000001
HostMax  : 10.10.10.254         00001010.00001010.00001010. 11111110
...

[Range 100:200]
RangeMin : 10.10.10.100
RangeMax : 10.10.10.200


netcalc -R 10:50 10.10.10.64/26
---
HostMin  : 10.10.10.65          00001010.00001010.00001010.01 000001
HostMax  : 10.10.10.126         00001010.00001010.00001010.01 111110
...

[Range 10:50]
RangeMin : 10.10.10.74
RangeMax : 10.10.10.114


netcalc -R 10:2000 10.20.0.0/16
---
HostMin  : 10.20.0.1            00001010.00010100. 00000000.00000001
HostMax  : 10.20.255.254        00001010.00010100. 11111111.11111110
...

[Range 10:2000]
RangeMin : 10.20.0.10
RangeMax : 10.20.7.208

debian directory improvements

Hi,

i tried to build debian package on current testing (buster) and it provides empty binary package. After small investigation, i have some suggestions to improve it:

Make its build dependencies to debhelper>10 (it is available in stable and via backport on oldstable too and it depends on dh_autoreconf, which is needed) and add bats into it (all test fails without it) into debian/control:

Build-Depends: debhelper (>= 10~), bats

Do not use native format, it is not recommended and it is a problem with it, if upstream (you) provides debian directory, you can read more at mentors, then i suggest to change debian/source/format to:

3.0 (quilt)

This requires to add debian's version into debian/changelog, eg.:

netcalc (2.1.4-1) unstable; urgency=medium

And finally, please do not install ipcalc symlink and remove conflict with it. From my point of view (as exmaintainer some official debian packages) it is too intrusive to force people to uninstall package, which can coexistent without any problems (i did it internally).

2.1 release tarball missing doc_DATA files

The README.md LICENSE ChangeLog.md files are missing from the release tarball.

As such make fails with:

make[2]: *** No rule to make target `ChangeLog.md', needed by `all-am'.  Stop.

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.