All Projects → zhanhb → cidr-merger

zhanhb / cidr-merger

Licence: MIT license
A simple command line tool to merge ip/ip cidr/ip range, supports IPv4/IPv6

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to cidr-merger

ip2location-csv-converter
This PHP script converts IP2Location CSV database into IP range or CIDR format.
Stars: ✭ 26 (-73.74%)
Mutual labels:  cidr, ip-range
server-ip-addresses
Daily updated list of IP addresses / CIDR blocks used by data centers, cloud service providers, servers, etc.
Stars: ✭ 74 (-25.25%)
Mutual labels:  cidr, ip-range
zip
PHP ZipArchive toolbox
Stars: ✭ 30 (-69.7%)
Mutual labels:  merge
Aehnlich
Show/Merge differences in directories and their content (text files) in Light/Dark designs
Stars: ✭ 73 (-26.26%)
Mutual labels:  merge
diffy
Tools for finding and manipulating differences between files
Stars: ✭ 47 (-52.53%)
Mutual labels:  merge
treediff-rs
Extract differences between arbitrary datastructures
Stars: ✭ 52 (-47.47%)
Mutual labels:  merge
php-merge
Php library to merge text. 3 way merge like git in php.
Stars: ✭ 26 (-73.74%)
Mutual labels:  merge
is-cidr
Check if a string is an IP address in CIDR notation
Stars: ✭ 27 (-72.73%)
Mutual labels:  cidr
git-json-merge
A git merge driver that use xdiff to automatically resolve merge conflicts in json files. This project was inspired by git-po-merge.
Stars: ✭ 86 (-13.13%)
Mutual labels:  merge
Nbdime
Tools for diffing and merging of Jupyter notebooks.
Stars: ✭ 2,135 (+2056.57%)
Mutual labels:  merge
Winmerge
WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.
Stars: ✭ 2,358 (+2281.82%)
Mutual labels:  merge
markdown-to-document
A Markdown CLI to easily generate HTML documents from Markdown files
Stars: ✭ 28 (-71.72%)
Mutual labels:  merge
PixelGlitch
Image glitch visualization using various Pixel Sorting methods for Processing
Stars: ✭ 25 (-74.75%)
Mutual labels:  merge
gitlab-merger-bot
GitLab Merger Bot
Stars: ✭ 23 (-76.77%)
Mutual labels:  merge
valve-matchmaking-ip-ranges
Lists of locations & IP addresses of Valve servers
Stars: ✭ 69 (-30.3%)
Mutual labels:  ip-range
HacktoberFest-HelloWorld
All your PRs will be merged !! 😊
Stars: ✭ 24 (-75.76%)
Mutual labels:  merge
Mergo
Written by Dario Castañé.
Stars: ✭ 1,808 (+1726.26%)
Mutual labels:  merge
git-rebase-via-merge
Fix rebase conflicts with minimum pain.
Stars: ✭ 41 (-58.59%)
Mutual labels:  merge
ronin-support
A support library for Ronin. Like activesupport, but for hacking!
Stars: ✭ 23 (-76.77%)
Mutual labels:  cidr
git-picked
List merged and cherry-picked branches
Stars: ✭ 30 (-69.7%)
Mutual labels:  merge

cidr-merger

A simple utility to merge ip/ip cidr/ip range, support IPv4/IPv6

$ cidr-merger --help
Usage: cidr-merger [OPTION]... [FILE]...
Write sorted result to standard output.

Options:
     --batch               batch mode (default if input files supplied or stdin
                           is not a tty), read file content into memory, then
                           write to the specified file
     --cidr                print as ip/cidr (default if not console mode)
 -c, --console             console mode(default if no input files supplied and
                           stdin is a tty), all input output files are ignored,
                           write to stdout immediately
     --empty-policy=value  indicate how to process empty input file
                             ignore(default): process as if it is not empty
                             skip: don't create output file
                             error: raise an error and exit
 -e, --error-if-empty      same as --empty-policy=error
 -h, --help                show this help menu
     --ignore-empty        same as --empty-policy=ignore
 -k, --skip-empty          same as --empty-policy=skip
     --merge               sort and merge input values (default)
     --original-order      output as the order of input, without merging
 -o, --output=file         output values to <file>, if multiple output files
                           specified, the count should be same as input files,
                           and will be processed respectively
 -r, --range               print as ip ranges
     --simple              output as single ip as possible (default)
                             ie. 192.168.1.2/32 -> 192.168.1.2
                                 192.168.1.2-192.168.1.2 -> 192.168.1.2
 -s, --standard            don't output as single ip
 -v, --version             show version info

Sample Usage:

$ echo '1.0.0.1-223.255.255.254' | cidr-merger
> 1.0.0.1
  1.0.0.2/31
  1.0.0.4/30
  1.0.0.8/29
  ......
  1.128.0.0/9
  2.0.0.0/7
  4.0.0.0/6
  8.0.0.0/5
  16.0.0.0/4
  32.0.0.0/3
  64.0.0.0/2
  128.0.0.0/2
  192.0.0.0/4
  208.0.0.0/5
  216.0.0.0/6
  220.0.0.0/7
  222.0.0.0/8
  223.0.0.0/9
  ......
  223.255.255.240/29
  223.255.255.248/30
  223.255.255.252/31
  223.255.255.254
$ echo '1.1.1.0' > a; \
    echo '1.1.1.1' > b; \
    echo '1.1.1.2/31' > c; \
    echo '1.1.1.3-1.1.1.7' > d; \
    cidr-merger -o merge a b c d; \
    cat merge; \
    rm a b c d merge
> 1.1.1.0/29
$ wget -O- "https://ftp.apnic.net/stats/apnic/`TZ=UTC date +%Y`/delegated-apnic-`TZ=UTC+24 date +%Y%m%d`.gz" | \
    gzip -d | awk -F\| '!/^\s*(#.*)?$/&&/CN\|ipv4/{print $4 "/" 32-log($5)/log(2)}' | \
    cidr-merger -eo/etc/chinadns_chnroute.txt # update ip on router
$ #              ^ e: means error if input is empty
$ echo 'fe80::/10' | cidr-merger -r
> fe80::-febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff
$ echo '1.1.1.0' > a; echo '1.1.1.1' | cidr-merger - a; rm a
$ #                                                ^ -: means standard input
> 1.1.1.0/31

Difference between standard and simple(default)

$ echo '1.1.1.1/32' | cidr-merger
> 1.1.1.1
$ echo '1.1.1.1/32' | cidr-merger -s
> 1.1.1.1/32
$ echo '1.1.1.1/32' | cidr-merger -r
> 1.1.1.1
$ echo '1.1.1.1/32' | cidr-merger -rs
> 1.1.1.1-1.1.1.1

Difference about empty policy

$ cidr-merger -o txt /dev/null # an empty file named `txt` is created.
$ cidr-merger -ko txt /dev/null # no file is created, and this program exit with code zero
$ #            ^ same as `cat /dev/null | cidr-merger --skip-empty --output txt`
$ cidr-merger -eo txt /dev/null # no file is created, and this program exit with code non zero
$ #            ^ same as `cat /dev/null | cidr-merger --error-if-empty --output txt`
$ # option `-e` might be useful when download file from internet and then write to a file

$ # There is no difference if you redirect output to a file such as following
$ cat /dev/null | cidr-merger -e > txt
  # file `txt` is created, but this program exit with code non zero
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].