The ipv6calc Homepage

Peter Bieringer

pb at bieringer dot de

Revision History
Revision 3.22011-10-29Revised by: PB

Table of Contents
1. General
1.1. Latest version
1.2. Included programs
1.3. Included databases
1.4. Possible external databases
2. License
3. Copyright
4. Author
5. Where to get sources or binaries
5.1. Latest version of sources:
5.2. Available formats:
5.3. Ready to use packages for several operating systems:
6. Configuring & Compiling
6.1. Configuring
6.2. Compiling
7. Mailling Lists
7.1. ipv6calc-announce
7.2. ipv6calc
8. Bug Reports
9. Features of ipv6calc
9.1. Description
9.2. List of built-in features
9.3. Examples
9.4. Option style
9.5. Online help
10. Webserver log conversion helper program "ipv6logconv"
10.1. Examples
11. Webserver log anonymization helper program "ipv6loganon"
11.1. Anonymization details
11.2. Supported log file formats
11.3. Supported options
11.4. Usage
12. Perl CGI wrapper program "ipv6calcweb.cgi"
12.1. Examples
13. Webserver log statistics helper program "ipv6logstats"
13.1. Supported options
13.2. Usage
13.3. Examples
14. History
14.1. 2011
14.2. 2010 and older

1. General

ipv6calc is a small utility written in programming language C to manipulate (not only) IPv6 addresses and is able to do other tricky things. Intentions were convering a given IPv6 address into compressed format, convering a given IPv6 address into the same format like shown in /proc/net/if_inet6 and (because it was not difficulty) migrating the Perl program ip6_int into. Now only one utiltity is needed to do a lot.

This utility was also used in the past to extend features on network-functions-ipv6 library, used by initscripts-ipv6.

Note: this tool got also its freshmeat / ipv6calc page (not maintained by the author)


1.1. Latest version

Latest version since last update of this page is 0.92.0 (released 2011-10-08)


1.2. Included programs

  • “ipv6calc”: the main utility

  • “ipv6calcweb”: CGI wrapper for ipv6calc's address information output

  • “ipv6logconv”: log converter (IPv4/IPv6)

  • “ipv6loganon”: log anonymizer (IPv4/IPv6)

  • “ipv6logstats”: log statistic generator (IPv4/IPv6)


1.3. Included databases

If not disabled during compiling the tool, following databases are statically included:

  • IEEE & OUI databases (for decoding vendor part of MAC/EUI-48)

  • IPv4 assignment database (for selecting proper registry in ipv6calcweb.cgi)

  • IPv6 database (for selecting proper registry in ipv6calcweb.cgi)


1.4. Possible external databases

If enabled during compiling the tool, following external (but local installed) databases can be used

  • GeoIP IPv4, IPv6 (since 0.90.0, req. GeoIP >= 1.4.5)

  • IP2Location IPv4, IPv6


2. License

The program is published under the GNU GPL version 2.


3. Copyright

(C) 2001 - 2011 by Dr. Peter Bieringer


4. Author

The author of ipv6calc is


5. Where to get sources or binaries


5.2. Available formats:

5.2.1. tar.gz

A SPEC file is included, so you can build a RPM from source tarball using

$ rpmbuild -ta path/to/ipv6calc-$version.tar.gz

5.2.2. as RPM

Currently only on rpmfind / ipv6calc, but there are plans to publish at least source RPMS on DeepSpace6 some day.


5.3. Ready to use packages for several operating systems:

5.3.1. Fedora Linux

Fedora 15 is the current developing platform, so use given hints above to create a RPM. Since Fedora 7 this package is included by default.


5.3.2. Red Hat Enterprise Linux and clones

It's tested by the developer that creation of the RPM is working fine on RHEL4. Since RHEL5 this package is included by default.


5.3.3. Mandrake Linux

Linux Mandrake is very similar to Red Hat Linux, therefore a rebuild should work, too.


5.3.4. Debian GNU/Linux

Package is maintained, more information can be found at http://packages.debian.org/ipv6calc


5.3.5. openSUSE

Package is maintained, more information can be found at http://download.opensuse.org/repositories/home:/uebelhacker/


6. Configuring & Compiling

6.1. Configuring

Following “ipc6calc” related configure options are currently supported (note: disabling the internal databases reduces the size of the resulting binary a lot):

  --disable-db-ieee       Disable IEEE database (default: enabled)
  --disable-db-ipv4       Disable IPv4 database (default: enabled)
  --disable-db-ipv6       Disable IPv6 database (default: enabled)

  --enable-ip2location    Enable IP2Location support (default: disabled)
  --enable-geoip          Enable GeoIP support (default: disabled) 
 
  --with-ip2location-headers=DIR
                          IP2Location include files location
  --with-ip2location-lib=DIR
                          IP2Location library location
  --with-ip2location-static
                          Explicitly link IP2Location statically (default=no)
  --with-ip2location-ipv4-default-file=file
                          Use a default IP2Location IPv4 database file when
                          ipv6calc is invoked with
                          '--db-ip2location-ipv4-default|-L'
  --with-ip2location-ipv6-default-file=file
                          Use a default IP2Location IPv6 database file when
                          ipv6calc is invoked with
                          '--db-ip2location-ipv6-default|-L'
  --with-geoip-headers=DIR
                          GeoIP include files location
  --with-geoip-lib=DIR    GeoIP library location
  --with-geoip-static     Explicitly link GeoIP statically (default=no)
  --with-geoip-ipv4-default-file=file
                          Use a default GeoIP IPv4 database file when ipv6calc
                          is invoked with '--db-geoip-ipv4-default|-G'
  --with-geoip-ipv6-default-file=file
                          Use a default GeoIP IPv6 database file when ipv6calc
                          is invoked with '--db-geoip-ipv6-default|-G'
  --with-geoip-ipv6-compat
                          Use IPv6 interface of GeoIP in compatibility mode
                          (supporting 1.4.5) 

6.2. Compiling

As usual, use

$ make

and run tests afterwards using

$ make test

or at least (e.g. if external databases are not available)

$ make test-minimal

7. Mailling Lists

7.1. ipv6calc-announce

Reason:

sending announcements of new versions

Traffic:

very low

Postings:

only moderators are allowed to post

Information:

DeepSpace6 / maillist ipv6calc-announce


7.2. ipv6calc

Reason:

discussions

Traffic:

low

Postings:

subscribers

Information:

DeepSpace6 / maillist ipv6calc


8. Bug Reports

You can send bug reports to the author himself or subscribe to maillist “ipv6calc” and send it to the list.


9. Features of ipv6calc

9.1. Description

The main program named “ipv6calc” is able to recognize many (not only) IPv6 address formats and depending on a selectable action (not required) a selectable output format can be specified. Also it has the capability to show detailed information of an IPv4/IPv6 address or anonymize it.


9.2. List of built-in features

Option “-v” shows built-in features, depending on configuration before compiling:

$ ./ipv6calc/ipv6calc -v 
ipv6calc: version 0.92.0 IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6

Option “-v -v” (since 0.91.0) shows built-in features in detail, depending on configuration before compiling:

$ ./ipv6calc/ipv6calc -v -v
ipv6calc: version 0.92.0 IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6

IEEE database included: IAB/20111008 OUI/20111008 
IPv4 database included: AFRINIC/20111008 APNIC/20111007 ARIN/20111007 IANA/20110203 LACNIC/20111006 RIPENCC/20111007
IPv6 database included: AFRINIC/20111008 APNIC/20111007 ARIN/20111007 IANA/20080827 LACNIC/20111006 RIPENCC/20111007

GeoIP support enabled, compiled with IPv4 & IPv6 support 
GeoIP dynamic library version (on this system): 1.4.8 
GeoIP IPv4 default file: /var/local/share/GeoIP/GeoIP.dat 
GeoIP IPv6 default file: /var/local/share/GeoIP/GeoIPv6.dat

IP2Location support enabled, compiled with API version: 4.0.2 
IP2Location IPv4 default file: /var/local/share/IP2Location/IP-COUNTRY-SAMPLE.BIN
IP2Location IPv6 default file: /var/local/share/IP2Location/IPV6-COUNTRY.BIN 

9.3. Examples

9.3.1. Conversion

A simple example is the conversion of an IPv6 address to a DNS PTR query string:

$ ./ipv6calc --out revnibbles.arpa 2001:db8::1
No input type specified, try autodetection...found type: ipv6addr
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.

Like you see, input format was autodetected. And the given example can be extended because ipv6calc also understands netmask / prefix length values:

$ ./ipv6calc -q --out revnibbles.arpa 2001:db8::1/64
0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.

Also you've also learnt now that switch '-q' (quiet) suppresses informational messages. You can use this now to start a DNS PTR query using:

$ dig PTR `./ipv6calc -q --out revnibbles.arpa 2001:db8::1/64`

But ipv6calc can do many more for you! Next example shows you the extraction of the IPv4 address contained in a 6to4 IPv6 address:

$ ./ipv6calc -q --action conv6to4 --in ipv6 2002:c0a8:fb61::1 --out ipv4
192.168.251.97

This also works vice-versa:

$ ./ipv6calc -q --action conv6to4 --in ipv4 192.168.251.97 --out ipv6
2002:c0a8:fb61::

There are many more features already implemented, if you miss one, send a note.


9.3.2. Information

Information about a simple IPv6 address:

$ ./ipv6calc -q -i 3ffe:ffff::210:a4ff:fe01:2345
Address type: unicast, 6bone, global-unicast, productive
Address type has SLA: 0000
Registry for address: reserved
Interface identifier: 0210:a4ff:fe01:2345
EUI-48/MAC address: 00:10:a4:01:23:45
MAC is a global unique one
MAC is an unicast one
OUI is: XIRCOM

Information about a Teredo IPv6 address:

$ ./ipv6calc -q -i 3ffe:831f:ce49:7601:8000:efff:af4a:86BF
Address type: unicast, 6bone, global-unicast, productive, teredo
IPv4 address: 80.181.121.64
IPv4 registry[80.181.121.64]: RIPENCC
IPv4 address: 206.73.118.1
IPv4 registry[206.73.118.1]: ARIN
Address type is Teredo and included IPv4 server address is: 80.181.121.64 and client port: 4096
IPv4 registry for Teredo server address: ARIN
Registry for address: reserved

There exists also a machine readable output (e.g. used by 'ipv6calcweb.cgi') - in addition, here IP2Location and/or GeoIP information can be displayed, if databases are specified.

$ ./ipv6calc -G -L -q -i -m 2a01:238:423d:8800:85b3:9e6b:3019:8909  
IPV6=2a01:0238:423d:8800:85b3:9e6b:3019:8909 
TYPE=unicast,global-unicast 
SLA=8800 
IPV6_REGISTRY=RIPENCC 
IID=85b3:9e6b:3019:8909 
EUI64_SCOPE=local 
IP2LOCATION_DATABASE_INFO_IPV6=url=http://www.ip2location.com date=2011-05-12 entries=24341 apiversion=4.0.2 
IP2LOCATION_COUNTRY_SHORT=DE 
IP2LOCATION_COUNTRY_LONG= 
GEOIP_COUNTRY_SHORT=DE 
GEOIP_COUNTRY_LONG=Germany 
GEOIP_DATABASE_INFO_IPV6=GEO-106FREE 20110501 Build 1 Copyright (c) 2011 MaxMind Inc All Rights Reserved apiversion=system 
IPV6CALC_NAME=ipv6calc 
IPV6CALC_VERSION=0.92.0 
IPV6CALC_COPYRIGHT="(P) & (C) 2001-2011 by Peter Bieringer <pb (at) bieringer.de>" 
IPV6CALC_OUTPUT_VERSION=5 
IPV6CALC_FEATURES="IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6" 

9.4. Option style

Since version 0.40 new-style option handling was introduced, using

  • --in <inputtype>

  • --out <outputtype>

  • --action <actiontype>

and many more conversions were added. A built-in check matrix should prevent misconversions.

Up to version 0.39, only old-style options (which perhaps - but it's not planned at the moment - are going obsolete sometimes the future) were available. They are one-in-all options, specifying input/action/output in one token. Internally this options will be converted into new-style options.


9.5. Online help

Online help always shows the currently implemented features.


9.5.1. Main online help:

IP2Location and GeoIP options only appear if compiled with such support.

$ ./ipv6calc -? 
ipv6calc: version 0.92.0 IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6 
(P) & (C) 2001-2011 by Peter Bieringer <pb (at) bieringer.de>

 General:   [-d|--debug <debug value>] : debug value (bitwise like)
  [-q|--quiet]               : be more quiet (auto-enabled in pipe mode)
  [-f|--flush]               : flush each line in pipe mode
  -v                         : show version (and included features)
  -v -v                      : show verbose version information

 Usage with new style options:
  [--in|-I <input type>]   : specify input  type
                             (default: autodetect)
  [--out|-O <output type>] : specify output type
                             (sometimes: autodetect)
  [--action|-A <action>]   : specify action
                             (default: format conversion, sometimes: autodetect)
  [<format option> ...] : specify format options
  <input data> [...]    : input data

  Available input  types:  [-m] --in     -?|-h|--help
  Available output types:  [-m] --out    -?|-h|--help
  Available action types:  [-m] --action -?|-h|--help

Other usage:
  --showinfo|-i [--machine_readable|-m] : show information about input data
  --showinfo|-i --show_types            : show available types on '-m'

  [--db-ip2location-ipv4 <file>] : IP2Location IPv4 database file (optional)
  [--db-ip2location-ipv6 <file>] : IP2Location IPv6 database file (optional)
  [--db-ip2location-ipv4-default|-L] : enable & use IP2Location IPv4 default database file (optional)
                                        /var/local/share/IP2Location/IP-COUNTRY-SAMPLE.BIN
  [--db-ip2location-ipv6-default|-L] : enable & use IP2Location IPv6 default database file (optional)
                                        /var/local/share/IP2Location/IPV6-COUNTRY.BIN

  [--db-geoip-ipv4 <file>]  : GeoIP IPv4 database file (optional)
  [--db-geoip-ipv6 <file>]  : GeoIP IPv6 database file (optional)
  [--db-geoip-ipv4-default|-G] : enable & use GeoIP IPv4 default database file (optional)
                                  /var/local/share/GeoIP/GeoIP.dat 
  [--db-geoip-ipv6-default|-G] : enable & use GeoIP IPv6 default database file (optional)
                                  /var/local/share/GeoIP/GeoIPv6.dat

 To see old-style option use: --printoldoptions 

9.5.2. Input-type options

$ ./ipv6calc --in -?
ipv6calc: version 0.92.0 IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6
(P) & (C) 2001-2011 by Peter Bieringer <pb (at) bieringer.de> 

 Available input types:
  auto           : automatic detection
  revnibbles.int : dot separated nibbles reverse, ending with ip6.int.
  revnibbles.arpa: dot separated nibbles reverse, ending with ip6.arpa.
  bitstring      : bitstring labes, ending with ip6.arpa.
  ipv6addr       : IPv6 address
  ipv4addr       : IPv4 address
  ipv4hex        : IPv4 in hexdecimal format
  ipv4revhex     : IPv4 in byte-reversed hexdecimal format
  mac            : MAC address (48 bits)
  base85         : Base-85 string
  ifinet6        : Like line in /proc/net/if_inet6
  iid+token      : Interface identifier and token
  ipv6logconv    : ipv6logconv (currently not supported)
  prefix+mac     : IPv6 prefix and a MAC address

9.5.3. Output-type options:

$ ./ipv6calc --out -?
ipv6calc: version 0.92.0 IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6
(P) & (C) 2001-2011 by Peter Bieringer <pb (at) bieringer.de> 

 Available output types:
  revnibbles.int : dot separated nibbles reverse, ending with ip6.int.
  revnibbles.arpa: dot separated nibbles reverse, ending with ip6.arpa.
  bitstring      : bitstring labes, ending with ip6.arpa.
  ipv6addr       : IPv6 address
  ipv4addr       : IPv4 address
  mac            : MAC address (48 bits)
  eui64          : EUI-64 identifier (64 bits)
  base85         : Base-85 string
  ifinet6        : Like line in /proc/net/if_inet6
  iid            : Interface identifier
  iid+token      : Interface identifier and token
  addrtype       : Address type
  ouitype        : OUI (IEEE) type
  ipv6addrtype   : IPv6 address type
  any            : any type (currently not supported)
  revipv4        : reverse IPv4, ending with in-addr.arpa
  ipv4hex        : IPv4 in hexdecimal format
  octal          : IP address in escaped octal format

 For examples and available format options use:
    --out <type> --examples

9.5.4. Action-type options:

$ ./ipv6calc --action -?
ipv6calc: version 0.92.0 IP2Location GeoIP GeoIPv6 DB_IEEE DB_IPV4 DB_IPV6
(P) & (C) 2001-2011 by Peter Bieringer <pb (at) bieringer.de> 

 Available action types:
  auto          : Automatic selection of action (default)
  geneui64      : Converts a MAC address to an EUI-64 address
  conv6to4      : Converts IPv4 address <-> 6to4 IPv6 address (prefix)
  genprivacyiid : Generates a privacy interface ID out of a given one and a token
  prefixmac2ipv6: Generates an IPv6 address out of a prefix and a MAC address
  anonymize        : Anonymize IPv4/IPv6 address without loosing much information
  6rd_local_prefix : Calculate the 6rd prefix from given IPv6 prefix & relay prefix and IPv4
                      Required options:
                       --6rd_prefix ...
                       --6rd_relay_prefix ... 

9.5.5. Because of historical issues, there exists also a support of the old-styled options:

$ ./ipv6calc --printoldoptions
ipv6calc: version 0.81.0
(P) & (C) 2001-2011 by Peter Bieringer <pb (at) bieringer.de>
 Usage with old style (shortcut) options (going obsolete): 
  <shortcut option> [<format option> ...] <input data> [...]

  --addr2ip6_int 
  --addr_to_ip6int
  --addr2ip6_arpa
  --addr_to_ip6arpa
  --addr_to_bitstring
  --addr2compaddr
  --addr_to_compressed
  --addr2uncompaddr
  --addr_to_uncompressed
  --addr_to_base85
  --base85_to_addr
  --mac_to_eui64
  --addr2fulluncompaddr
  --addr_to_fulluncompressed
  --addr2if_inet6
  --addr_to_ifinet6
  --if_inet62addr
  --ifinet6_to_compressed
  --eui64_to_privacy
  --ipv4_to_6to4addr

10. Webserver log conversion helper program "ipv6logconv"

This program parses address tokens of a given webserver logfile and converts them to special strings, useful for statistics (e.g. created by using "analog").


10.1. Examples

A demonstration about which kind of statistics are possible to produce is shown at http://www.ipv6.bieringer.de/ (IPv6 only).


11. Webserver log anonymization helper program "ipv6loganon"

On autoconfiguration, the interface part of an IPv6 address is based on the MAC address of the network interface card (NIC). This address is used for outgoing requests, if privacy option (RFC3041 / RFC4941) is not enabled. This results in many privacy related information on web- or mail-server log files. Administrators, which won't (be allowed to) store such information over time, but still do not want to loose information about address type distribution should use 'ipv6loganon' to anonymize their log files.


11.1. Anonymization details

The anonymizer would keep as much information as possible for IPv6 address types.

Client-side IID would be anonymized by

  • UI-48 based: serial number would be zero'ed, keeping OID

  • EUI-64 based: serial number would be zero'ed, keeping OID

  • ISATAP: client IPv4 address would be anonymized by given IPv4 mask

  • TEREDO: client IPv4 address would be anonymized by given IPv4 mask, client port would be zero'ed

  • 6to4(Microsoft): client IPv4 address would be anonymized by given IPv4 mask

  • local: whole IID would be zero'ed

Client-side SLA would be anonymized by

  • SLA would be zero'ed

Prefix would be anonymized by

  • 6to4: client IPv4 address would be anonymized by given IPv4 mask

Compat/Mapped IPv4 addresses would be anonymized by

  • IPv4 address would be anonymized by given IPv4 mask


11.2. Supported log file formats

Currently native supported log files:

  • Apache log file format, 1st token is IPv4 or IPv6 address

There are plans to support also mail server log files sometimes in the future, but because of different formats, this would be probably done by a Perl program which parses the log file and a (cached) 'ip6calc' call with action 'anonymize'.


11.3. Supported options

$ ./ipv6loganon -?
ipv6loganon: version 0.81.0
(P) & (C) 2007-2011 by Peter Bieringer <pb (at) bieringer.de>

This program anonymizes IPv4/IPv6 addresses in HTTP server log files

 General:
  [-d|--debug <debug value>] : debug value (bitwise like)
  [-V|--verbose] : be verbose
  [-n|--nocache] : disable caching
  [-c|--cachelimit <value>] : set cache limit
                               default: 20
                               maximum: 200
 Output anonymization:
  --mask-ipv4 <bits>     : mask all IPv4 addresses [0-32], default 24
                            even if occurs in IPv6-IID
  --mask-ipv6 <bits>     : mask IPv6 prefix [0-64], default 48
                            only applied to related address types
  --no-mask-iid          : do not mask non-IPv4 based IPv6-IID
  --anonymize-standard   : preset for standard anonymization (default)
                            mask-ipv4=24 mask-ipv6=48 mask-iid
  --anonymize-careful    : preset for careful anonymization
                            mask-ipv4=20 mask-ipv6=40 mask-iid
  --anonymize-paranoid   : preset for paranoid anonymization
                            mask-ipv4=16 mask-ipv6=32 mask-iid

 Takes data from stdin, outputs the processed data to stdout

11.4. Usage

11.4.1. Offline anonymization

$ cat /path/to/http_log | ./ipv6loganon >/path/to/http_log_anonymized

11.4.2. On-the-fly online anonymization

(Supported since 0.90.0)

Adjust httpd.conf like following:

CustomLog "|/usr/local/bin/ipv6loganon -a -f /var/log/httpd/access_log" combined

In case of “cronolog” is used on the system, configure like this:

CustomLog "|/usr/bin/ipv6loganon -f |/usr/sbin/cronolog /var/log/httpd/access.log-%Y%m%d" combined 

12. Perl CGI wrapper program "ipv6calcweb.cgi"

Because calling C programs directly as CGI isn't really recommended (too much security troubles all the time), I wrote a small wrapper utility which calls "ipv6calc" to get information about client and server address for displaying on a web page.


12.1. Examples

A demonstration about which kind of output is possible to produce is shown at


13. Webserver log statistics helper program "ipv6logstats"

This program parses a given webserver logfile and count addresses, useful for time period statistics.


13.1. Supported options

$ ./ipv6logstats -?
ipv6logstats: version 0.81.0
(P) & (C) 2007-2011 by Peter Bieringer <pb (at) bieringer.de>

 General:
  [-d|--debug <debug value>] : debug value (bitwise like)
  [-u|--unknown]             : print unknown IP addresses to stderr
  [-c|--colums]              : print statistics in colums
  [-n|--noheader]            : don't print header in colums mode
  [-o|--onlyheader]          : print only header in colums mode
  [-p|--prefix <token>]      : print token as prefix

 Takes http log data from stdin and print a table on output

13.2. Usage

There are a README and some helper scripts available in the package how to use this program and how to generate a graph using Gnuplot.


13.3. Examples

A demonstration with real data is available at http://mirrors.bieringer.de/stats/timeline.html.


14. History

Major extensions/changes are listed here


14.1. 2011

  • ipv6calc/ipv6calcweb.cgi: enable included GeoIP support with IPv6 (usable with GeoIP >= 1.4.5)

  • ipv6calc: extend for 6rd support (--action 6rd_local_prefix --6rd_prefix <PREFIX> --6rd_relay_prefix <RELAY_PREFIX>)

  • ipv6calc: enable stdin support for bulk transformation

  • ipv6calc: add support for NAT64 address type

  • ipv6calc: add option “forceprefix <LENGTH>” to print prefix of an address without a given prefix length

  • ipv6loganon: extend for pipe usage (e.g. in Apache log file directive) and write/append to specified file

  • General: add configure options to disable built-in databases (reduce binary size a lot, e.g. for embedded devices)