diff --git a/README.md b/README.md
index 07d29f9a..092f1100 100644
--- a/README.md
+++ b/README.md
@@ -189,6 +189,7 @@ option.
| ` --ini` | INI file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ini) |
| ` --iostat` | `iostat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iostat) |
| ` --iostat-s` | `iostat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iostat_s) |
+| ` --ip-address` | IP Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ip_address) |
| ` --iptables` | `iptables` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iptables) |
| ` --iso-datetime` | ISO 8601 Datetime string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iso_datetime) |
| ` --iw-scan` | `iw dev [device] scan` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iw_scan) |
@@ -432,15 +433,16 @@ Local plugins may override default parsers.
#### Locale
-For best results set the `LANG` locale environment variable to `C` or
-`en_US.UTF-8`. For example, either by setting directly on the command-line:
+For best results set the locale environment variables to `C` or
+`en_US.UTF-8` by modifying the `LC_ALL` variable:
```
-$ LANG=C date | jc --date
+$ LC_ALL=C date | jc --date
```
-or by exporting to the environment before running commands:
+You can also set the locale variables individually:
```
$ export LANG=C
+$ export LC_NUMERIC=C
```
On some older systems UTF-8 output will be downgraded to ASCII with `\\u`
diff --git a/completions/jc_bash_completion.sh b/completions/jc_bash_completion.sh
index 6df9299d..cac8256d 100644
--- a/completions/jc_bash_completion.sh
+++ b/completions/jc_bash_completion.sh
@@ -4,7 +4,7 @@ _jc()
jc_about_options jc_about_mod_options jc_help_options jc_special_options
jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lsusb md5 md5sum mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo)
- jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --chage --cksum --crontab --crontab-u --csv --csv-s --date --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --iptables --iso-datetime --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lsusb --m3u --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --postconf --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
+ jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --chage --cksum --crontab --crontab-u --csv --csv-s --date --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iso-datetime --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lsusb --m3u --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --postconf --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
jc_options=(--force-color -C --debug -d --monochrome -m --pretty -p --quiet -q --raw -r --unbuffer -u --yaml-out -y)
jc_about_options=(--about -a)
jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C)
diff --git a/completions/jc_zsh_completion.sh b/completions/jc_zsh_completion.sh
index 93f27005..c65c4b90 100644
--- a/completions/jc_zsh_completion.sh
+++ b/completions/jc_zsh_completion.sh
@@ -94,7 +94,7 @@ _jc() {
'xrandr:run "xrandr" command with magic syntax.'
'zipinfo:run "zipinfo" command with magic syntax.'
)
- jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --chage --cksum --crontab --crontab-u --csv --csv-s --date --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --iptables --iso-datetime --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lsusb --m3u --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --postconf --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
+ jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --chage --cksum --crontab --crontab-u --csv --csv-s --date --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iso-datetime --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lsusb --m3u --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --postconf --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
jc_parsers_describe=(
'--acpi:`acpi` command parser'
'--airport:`airport -I` command parser'
@@ -137,6 +137,7 @@ _jc() {
'--ini:INI file parser'
'--iostat:`iostat` command parser'
'--iostat-s:`iostat` command streaming parser'
+ '--ip-address:IP Address string parser'
'--iptables:`iptables` command parser'
'--iso-datetime:ISO 8601 Datetime string parser'
'--iw-scan:`iw dev [device] scan` command parser'
diff --git a/docs/parsers/ip_address.md b/docs/parsers/ip_address.md
new file mode 100644
index 00000000..e98bda7a
--- /dev/null
+++ b/docs/parsers/ip_address.md
@@ -0,0 +1,490 @@
+[Home](https://kellyjonbrazil.github.io/jc/)
+
+
+# jc.parsers.ip\_address
+
+jc - JSON Convert IP Address string parser
+
+Accepts standard and integer IP address notation for both IPv4 and IPv6
+addresses. CIDR subnet mask and Scope ID is also allowed for standard
+notation. See examples below.
+
+Usage (cli):
+
+ $ echo '192.168.1.1' | jc --ip-address
+
+Usage (module):
+
+ import jc
+ result = jc.parse('ip_address', ip_address_string)
+
+Schema:
+
+ {
+ "version": integer,
+ "max_prefix_length": integer,
+ "ip": string,
+ "ip_compressed": string,
+ "ip_exploded": string,
+ "scope_id": string/null,
+ "ipv4_mapped": string/null,
+ "six_to_four": string/null,
+ "teredo_client": string/null,
+ "teredo_server": string/null,
+ "dns_ptr": string,
+ "network": string,
+ "broadcast": string,
+ "hostmask": string,
+ "netmask": string,
+ "cidr_netmask": integer,
+ "hosts": integer,
+ "first_host": string,
+ "last_host": string,
+ "is_multicast": boolean,
+ "is_private": boolean,
+ "is_global": boolean,
+ "is_link_local": boolean,
+ "is_loopback": boolean,
+ "is_reserved": boolean,
+ "is_unspecified": boolean,
+ "int": {
+ "ip": integer,
+ "network": integer,
+ "broadcast": integer,
+ "first_host": integer,
+ "last_host": integer
+ },
+ "hex": {
+ "ip": string,
+ "network": string,
+ "broadcast": string,
+ "hostmask": string,
+ "netmask": string,
+ "first_host": string,
+ "last_host": string
+ },
+ "bin": {
+ "ip": string,
+ "network": string,
+ "broadcast": string,
+ "hostmask": string,
+ "netmask": string,
+ "first_host": string,
+ "last_host": string
+ }
+ }
+
+Examples:
+
+ $ echo 192.168.2.10/24 | jc --ip-address -p
+ {
+ "version": 4,
+ "max_prefix_length": 32,
+ "ip": "192.168.2.10",
+ "ip_compressed": "192.168.2.10/24",
+ "ip_exploded": "192.168.2.10/24",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "10.2.168.192.in-addr.arpa",
+ "network": "192.168.2.0",
+ "broadcast": "192.168.2.255",
+ "hostmask": "0.0.0.255",
+ "netmask": "255.255.255.0",
+ "cidr_netmask": 24,
+ "hosts": 254,
+ "first_host": "192.168.2.1",
+ "last_host": "192.168.2.254",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 3232236042,
+ "network": 3232236032,
+ "broadcast": 3232236287,
+ "first_host": 3232236033,
+ "last_host": 3232236286
+ },
+ "hex": {
+ "ip": "c0:a8:02:0a",
+ "network": "c0:a8:02:00",
+ "broadcast": "c0:a8:02:ff",
+ "hostmask": "00:00:00:ff",
+ "netmask": "ff:ff:ff:00",
+ "first_host": "c0:a8:02:01",
+ "last_host": "c0:a8:02:fe"
+ },
+ "bin": {
+ "ip": "11000000101010000000001000001010",
+ "network": "11000000101010000000001000000000",
+ "broadcast": "11000000101010000000001011111111",
+ "hostmask": "00000000000000000000000011111111",
+ "netmask": "11111111111111111111111100000000",
+ "first_host": "11000000101010000000001000000001",
+ "last_host": "11000000101010000000001011111110"
+ }
+ }
+
+ $ echo 3232236042 | jc --ip-address -p
+ {
+ "version": 4,
+ "max_prefix_length": 32,
+ "ip": "192.168.2.10",
+ "ip_compressed": "192.168.2.10/32",
+ "ip_exploded": "192.168.2.10/32",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "10.2.168.192.in-addr.arpa",
+ "network": "192.168.2.10",
+ "broadcast": "192.168.2.10",
+ "hostmask": "0.0.0.0",
+ "netmask": "255.255.255.255",
+ "cidr_netmask": 32,
+ "hosts": 1,
+ "first_host": "192.168.2.10",
+ "last_host": "192.168.2.10",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 3232236042,
+ "network": 3232236042,
+ "broadcast": 3232236042,
+ "first_host": 3232236042,
+ "last_host": 3232236042
+ },
+ "hex": {
+ "ip": "c0:a8:02:0a",
+ "network": "c0:a8:02:0a",
+ "broadcast": "c0:a8:02:0a",
+ "hostmask": "00:00:00:00",
+ "netmask": "ff:ff:ff:ff",
+ "first_host": "c0:a8:02:0a",
+ "last_host": "c0:a8:02:0a"
+ },
+ "bin": {
+ "ip": "11000000101010000000001000001010",
+ "network": "11000000101010000000001000001010",
+ "broadcast": "11000000101010000000001000001010",
+ "hostmask": "00000000000000000000000000000000",
+ "netmask": "11111111111111111111111111111111",
+ "first_host": "11000000101010000000001000001010",
+ "last_host": "11000000101010000000001000001010"
+ }
+ }
+
+ $ echo 127:0:de::1%128/96 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "127:0:de::1",
+ "ip_compressed": "127:0:de::1%128/96",
+ "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001/96",
+ "scope_id": "128",
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.....0.7.2.1.0.ip6.arpa",
+ "network": "127:0:de::",
+ "broadcast": "127:0:de::ffff:ffff",
+ "hostmask": "::ffff:ffff",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff::",
+ "cidr_netmask": 96,
+ "hosts": 4294967294,
+ "first_host": "127:0:de::1",
+ "last_host": "127:0:de::ffff:fffe",
+ "is_multicast": false,
+ "is_private": false,
+ "is_global": true,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": true,
+ "is_unspecified": false,
+ "int": {
+ "ip": 1531727573536155682370944093904699393,
+ "network": 1531727573536155682370944093904699392,
+ "broadcast": 1531727573536155682370944098199666687,
+ "first_host": 1531727573536155682370944093904699393,
+ "last_host": 1531727573536155682370944098199666686
+ },
+ "hex": {
+ "ip": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "network": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:00",
+ "broadcast": "01:27:00:00:00:de:00:00:00:00:00:00:ff:ff:ff:ff",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:ff:ff:ff:ff",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:00:00:00:00",
+ "first_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "last_host": "01:27:00:00:00:de:00:00:00:00:00:00:ff:ff:ff:fe"
+ },
+ "bin": {
+ "ip": "000000010010011100000000000000000000000011011110000000...",
+ "network": "0000000100100111000000000000000000000000110111100...",
+ "broadcast": "00000001001001110000000000000000000000001101111...",
+ "hostmask": "000000000000000000000000000000000000000000000000...",
+ "netmask": "1111111111111111111111111111111111111111111111111...",
+ "first_host": "0000000100100111000000000000000000000000110111...",
+ "last_host": "00000001001001110000000000000000000000001101111..."
+ }
+ }
+
+ $ echo 1531727573536155682370944093904699393 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "127:0:de::1",
+ "ip_compressed": "127:0:de::1/128",
+ "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001/128",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "1.0.0.0.0.0.0....0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
+ "network": "127:0:de::1",
+ "broadcast": "127:0:de::1",
+ "hostmask": "::",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "cidr_netmask": 128,
+ "hosts": 1,
+ "first_host": "127:0:de::1",
+ "last_host": "127:0:de::1",
+ "is_multicast": false,
+ "is_private": false,
+ "is_global": true,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": true,
+ "is_unspecified": false,
+ "int": {
+ "ip": 1531727573536155682370944093904699393,
+ "network": 1531727573536155682370944093904699393,
+ "broadcast": 1531727573536155682370944093904699393,
+ "first_host": 1531727573536155682370944093904699393,
+ "last_host": 1531727573536155682370944093904699393
+ },
+ "hex": {
+ "ip": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "network": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "broadcast": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "first_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "last_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01"
+ },
+ "bin": {
+ "ip": "0000000100100111000000000000000000000000110111100000000...",
+ "network": "00000001001001110000000000000000000000001101111000...",
+ "broadcast": "000000010010011100000000000000000000000011011110...",
+ "hostmask": "0000000000000000000000000000000000000000000000000...",
+ "netmask": "11111111111111111111111111111111111111111111111111...",
+ "first_host": "00000001001001110000000000000000000000001101111...",
+ "last_host": "000000010010011100000000000000000000000011011110..."
+ }
+ }
+
+ # IPv4 Mapped Address
+ $ echo ::FFFF:192.168.1.35 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "::ffff:c0a8:123",
+ "ip_compressed": "::ffff:c0a8:123/128",
+ "ip_exploded": "0000:0000:0000:0000:0000:ffff:c0a8:0123/128",
+ "scope_id": null,
+ "ipv4_mapped": "192.168.1.35",
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0.0....0.0.0.0.0.0.0.ip6.arpa",
+ "network": "::ffff:c0a8:123",
+ "broadcast": "::ffff:c0a8:123",
+ "hostmask": "::",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "cidr_netmask": 128,
+ "hosts": 1,
+ "first_host": "::ffff:c0a8:123",
+ "last_host": "::ffff:c0a8:123",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": true,
+ "is_unspecified": false,
+ "int": {
+ "ip": 281473913979171,
+ "network": 281473913979171,
+ "broadcast": 281473913979171,
+ "first_host": 281473913979171,
+ "last_host": 281473913979171
+ },
+ "hex": {
+ "ip": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "network": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "broadcast": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "first_host": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "last_host": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23"
+ },
+ "bin": {
+ "ip": "0000000000000000000000000000000000000000000000000000000...",
+ "network": "00000000000000000000000000000000000000000000000000...",
+ "broadcast": "000000000000000000000000000000000000000000000000...",
+ "hostmask": "0000000000000000000000000000000000000000000000000...",
+ "netmask": "11111111111111111111111111111111111111111111111111...",
+ "first_host": "00000000000000000000000000000000000000000000000...",
+ "last_host": "000000000000000000000000000000000000000000000000..."
+ }
+ }
+
+ # 6to4 Address
+ $ echo 2002:c000:204::/48 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "2002:c000:204::",
+ "ip_compressed": "2002:c000:204::/48",
+ "ip_exploded": "2002:c000:0204:0000:0000:0000:0000:0000/48",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": "192.0.2.4",
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "0.0.0.0.0.0.0.0......0.4.0.2.0.0.0.0.c.2.0.0.2.ip6.arpa",
+ "network": "2002:c000:204::",
+ "broadcast": "2002:c000:204:ffff:ffff:ffff:ffff:ffff",
+ "hostmask": "::ffff:ffff:ffff:ffff:ffff",
+ "netmask": "ffff:ffff:ffff::",
+ "cidr_netmask": 48,
+ "hosts": 1208925819614629174706174,
+ "first_host": "2002:c000:204::1",
+ "last_host": "2002:c000:204:ffff:ffff:ffff:ffff:fffe",
+ "is_multicast": false,
+ "is_private": false,
+ "is_global": true,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 42549574682102084431821433448024768512,
+ "network": 42549574682102084431821433448024768512,
+ "broadcast": 42549574682103293357641048077199474687,
+ "first_host": 42549574682102084431821433448024768513,
+ "last_host": 42549574682103293357641048077199474686
+ },
+ "hex": {
+ "ip": "20:02:c0:00:02:04:00:00:00:00:00:00:00:00:00:00",
+ "network": "20:02:c0:00:02:04:00:00:00:00:00:00:00:00:00:00",
+ "broadcast": "20:02:c0:00:02:04:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "hostmask": "00:00:00:00:00:00:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "netmask": "ff:ff:ff:ff:ff:ff:00:00:00:00:00:00:00:00:00:00",
+ "first_host": "20:02:c0:00:02:04:00:00:00:00:00:00:00:00:00:01",
+ "last_host": "20:02:c0:00:02:04:ff:ff:ff:ff:ff:ff:ff:ff:ff:fe"
+ },
+ "bin": {
+ "ip": "0010000000000010110000000000000000000010000001000000000...",
+ "network": "00100000000000101100000000000000000000100000010000...",
+ "broadcast": "001000000000001011000000000000000000001000000100...",
+ "hostmask": "0000000000000000000000000000000000000000000000001...",
+ "netmask": "11111111111111111111111111111111111111111111111100...",
+ "first_host": "00100000000000101100000000000000000000100000010...",
+ "last_host": "001000000000001011000000000000000000001000000100..."
+ }
+ }
+
+ # Teredo Address
+ % echo 2001:0000:4136:e378:8000:63bf:3fff:fdd2 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "ip_compressed": "2001:0:4136:e378:8000:63bf:3fff:fdd2/128",
+ "ip_exploded": "2001:0000:4136:e378:8000:63bf:3fff:fdd2/128",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": "192.0.2.45",
+ "teredo_server": "65.54.227.120",
+ "dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0....0.0.0.1.0.0.2.ip6.arpa",
+ "network": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "broadcast": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "hostmask": "::",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "cidr_netmask": 128,
+ "hosts": 1,
+ "first_host": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "last_host": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 42540488182158724593221357832373272018,
+ "network": 42540488182158724593221357832373272018,
+ "broadcast": 42540488182158724593221357832373272018,
+ "first_host": 42540488182158724593221357832373272018,
+ "last_host": 42540488182158724593221357832373272018
+ },
+ "hex": {
+ "ip": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "network": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "broadcast": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "first_host": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "last_host": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2"
+ },
+ "bin": {
+ "ip": "001000000000000100000000000000000100000100110110111000...",
+ "network": "0010000000000001000000000000000001000001001101101...",
+ "broadcast": "00100000000000010000000000000000010000010011011...",
+ "hostmask": "000000000000000000000000000000000000000000000000...",
+ "netmask": "1111111111111111111111111111111111111111111111111...",
+ "first_host": "0010000000000001000000000000000001000001001101...",
+ "last_host": "00100000000000010000000000000000010000010011011..."
+ }
+ }
+
+
+
+### parse
+
+```python
+def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict
+```
+
+Main text parsing function
+
+Parameters:
+
+ data: (string) text data to parse
+ raw: (boolean) unprocessed output if True
+ quiet: (boolean) suppress warning messages if True
+
+Returns:
+
+ Dictionary. Raw or processed structured data.
+
+### Parser Information
+Compatibility: linux, darwin, cygwin, win32, aix, freebsd
+
+Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
diff --git a/jc/parsers/ip_address.py b/jc/parsers/ip_address.py
index 2715b39a..1af86f7a 100644
--- a/jc/parsers/ip_address.py
+++ b/jc/parsers/ip_address.py
@@ -1,5 +1,9 @@
"""jc - JSON Convert IP Address string parser
+Accepts standard and integer IP address notation for both IPv4 and IPv6
+addresses. CIDR subnet mask and Scope ID is also allowed for standard
+notation. See examples below.
+
Usage (cli):
$ echo '192.168.1.1' | jc --ip-address
@@ -11,21 +15,449 @@ Usage (module):
Schema:
- [
- {
- "ip_address": string,
- "bar": boolean,
- "baz": integer
+ {
+ "version": integer,
+ "max_prefix_length": integer,
+ "ip": string,
+ "ip_compressed": string,
+ "ip_exploded": string,
+ "scope_id": string/null,
+ "ipv4_mapped": string/null,
+ "six_to_four": string/null,
+ "teredo_client": string/null,
+ "teredo_server": string/null,
+ "dns_ptr": string,
+ "network": string,
+ "broadcast": string,
+ "hostmask": string,
+ "netmask": string,
+ "cidr_netmask": integer,
+ "hosts": integer,
+ "first_host": string,
+ "last_host": string,
+ "is_multicast": boolean,
+ "is_private": boolean,
+ "is_global": boolean,
+ "is_link_local": boolean,
+ "is_loopback": boolean,
+ "is_reserved": boolean,
+ "is_unspecified": boolean,
+ "int": {
+ "ip": integer,
+ "network": integer,
+ "broadcast": integer,
+ "first_host": integer,
+ "last_host": integer
+ },
+ "hex": {
+ "ip": string,
+ "network": string,
+ "broadcast": string,
+ "hostmask": string,
+ "netmask": string,
+ "first_host": string,
+ "last_host": string
+ },
+ "bin": {
+ "ip": string,
+ "network": string,
+ "broadcast": string,
+ "hostmask": string,
+ "netmask": string,
+ "first_host": string,
+ "last_host": string
}
- ]
+ }
Examples:
- $ ip_address | jc --ip_address -p
- []
+ $ echo 192.168.2.10/24 | jc --ip-address -p
+ {
+ "version": 4,
+ "max_prefix_length": 32,
+ "ip": "192.168.2.10",
+ "ip_compressed": "192.168.2.10/24",
+ "ip_exploded": "192.168.2.10/24",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "10.2.168.192.in-addr.arpa",
+ "network": "192.168.2.0",
+ "broadcast": "192.168.2.255",
+ "hostmask": "0.0.0.255",
+ "netmask": "255.255.255.0",
+ "cidr_netmask": 24,
+ "hosts": 254,
+ "first_host": "192.168.2.1",
+ "last_host": "192.168.2.254",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 3232236042,
+ "network": 3232236032,
+ "broadcast": 3232236287,
+ "first_host": 3232236033,
+ "last_host": 3232236286
+ },
+ "hex": {
+ "ip": "c0:a8:02:0a",
+ "network": "c0:a8:02:00",
+ "broadcast": "c0:a8:02:ff",
+ "hostmask": "00:00:00:ff",
+ "netmask": "ff:ff:ff:00",
+ "first_host": "c0:a8:02:01",
+ "last_host": "c0:a8:02:fe"
+ },
+ "bin": {
+ "ip": "11000000101010000000001000001010",
+ "network": "11000000101010000000001000000000",
+ "broadcast": "11000000101010000000001011111111",
+ "hostmask": "00000000000000000000000011111111",
+ "netmask": "11111111111111111111111100000000",
+ "first_host": "11000000101010000000001000000001",
+ "last_host": "11000000101010000000001011111110"
+ }
+ }
- $ ip_address | jc --ip_address -p -r
- []
+ $ echo 3232236042 | jc --ip-address -p
+ {
+ "version": 4,
+ "max_prefix_length": 32,
+ "ip": "192.168.2.10",
+ "ip_compressed": "192.168.2.10/32",
+ "ip_exploded": "192.168.2.10/32",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "10.2.168.192.in-addr.arpa",
+ "network": "192.168.2.10",
+ "broadcast": "192.168.2.10",
+ "hostmask": "0.0.0.0",
+ "netmask": "255.255.255.255",
+ "cidr_netmask": 32,
+ "hosts": 1,
+ "first_host": "192.168.2.10",
+ "last_host": "192.168.2.10",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 3232236042,
+ "network": 3232236042,
+ "broadcast": 3232236042,
+ "first_host": 3232236042,
+ "last_host": 3232236042
+ },
+ "hex": {
+ "ip": "c0:a8:02:0a",
+ "network": "c0:a8:02:0a",
+ "broadcast": "c0:a8:02:0a",
+ "hostmask": "00:00:00:00",
+ "netmask": "ff:ff:ff:ff",
+ "first_host": "c0:a8:02:0a",
+ "last_host": "c0:a8:02:0a"
+ },
+ "bin": {
+ "ip": "11000000101010000000001000001010",
+ "network": "11000000101010000000001000001010",
+ "broadcast": "11000000101010000000001000001010",
+ "hostmask": "00000000000000000000000000000000",
+ "netmask": "11111111111111111111111111111111",
+ "first_host": "11000000101010000000001000001010",
+ "last_host": "11000000101010000000001000001010"
+ }
+ }
+
+ $ echo 127:0:de::1%128/96 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "127:0:de::1",
+ "ip_compressed": "127:0:de::1%128/96",
+ "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001/96",
+ "scope_id": "128",
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.....0.7.2.1.0.ip6.arpa",
+ "network": "127:0:de::",
+ "broadcast": "127:0:de::ffff:ffff",
+ "hostmask": "::ffff:ffff",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff::",
+ "cidr_netmask": 96,
+ "hosts": 4294967294,
+ "first_host": "127:0:de::1",
+ "last_host": "127:0:de::ffff:fffe",
+ "is_multicast": false,
+ "is_private": false,
+ "is_global": true,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": true,
+ "is_unspecified": false,
+ "int": {
+ "ip": 1531727573536155682370944093904699393,
+ "network": 1531727573536155682370944093904699392,
+ "broadcast": 1531727573536155682370944098199666687,
+ "first_host": 1531727573536155682370944093904699393,
+ "last_host": 1531727573536155682370944098199666686
+ },
+ "hex": {
+ "ip": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "network": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:00",
+ "broadcast": "01:27:00:00:00:de:00:00:00:00:00:00:ff:ff:ff:ff",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:ff:ff:ff:ff",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:00:00:00:00",
+ "first_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "last_host": "01:27:00:00:00:de:00:00:00:00:00:00:ff:ff:ff:fe"
+ },
+ "bin": {
+ "ip": "000000010010011100000000000000000000000011011110000000...",
+ "network": "0000000100100111000000000000000000000000110111100...",
+ "broadcast": "00000001001001110000000000000000000000001101111...",
+ "hostmask": "000000000000000000000000000000000000000000000000...",
+ "netmask": "1111111111111111111111111111111111111111111111111...",
+ "first_host": "0000000100100111000000000000000000000000110111...",
+ "last_host": "00000001001001110000000000000000000000001101111..."
+ }
+ }
+
+ $ echo 1531727573536155682370944093904699393 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "127:0:de::1",
+ "ip_compressed": "127:0:de::1/128",
+ "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001/128",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "1.0.0.0.0.0.0....0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
+ "network": "127:0:de::1",
+ "broadcast": "127:0:de::1",
+ "hostmask": "::",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "cidr_netmask": 128,
+ "hosts": 1,
+ "first_host": "127:0:de::1",
+ "last_host": "127:0:de::1",
+ "is_multicast": false,
+ "is_private": false,
+ "is_global": true,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": true,
+ "is_unspecified": false,
+ "int": {
+ "ip": 1531727573536155682370944093904699393,
+ "network": 1531727573536155682370944093904699393,
+ "broadcast": 1531727573536155682370944093904699393,
+ "first_host": 1531727573536155682370944093904699393,
+ "last_host": 1531727573536155682370944093904699393
+ },
+ "hex": {
+ "ip": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "network": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "broadcast": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "first_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01",
+ "last_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01"
+ },
+ "bin": {
+ "ip": "0000000100100111000000000000000000000000110111100000000...",
+ "network": "00000001001001110000000000000000000000001101111000...",
+ "broadcast": "000000010010011100000000000000000000000011011110...",
+ "hostmask": "0000000000000000000000000000000000000000000000000...",
+ "netmask": "11111111111111111111111111111111111111111111111111...",
+ "first_host": "00000001001001110000000000000000000000001101111...",
+ "last_host": "000000010010011100000000000000000000000011011110..."
+ }
+ }
+
+ # IPv4 Mapped Address
+ $ echo ::FFFF:192.168.1.35 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "::ffff:c0a8:123",
+ "ip_compressed": "::ffff:c0a8:123/128",
+ "ip_exploded": "0000:0000:0000:0000:0000:ffff:c0a8:0123/128",
+ "scope_id": null,
+ "ipv4_mapped": "192.168.1.35",
+ "six_to_four": null,
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0.0....0.0.0.0.0.0.0.ip6.arpa",
+ "network": "::ffff:c0a8:123",
+ "broadcast": "::ffff:c0a8:123",
+ "hostmask": "::",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "cidr_netmask": 128,
+ "hosts": 1,
+ "first_host": "::ffff:c0a8:123",
+ "last_host": "::ffff:c0a8:123",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": true,
+ "is_unspecified": false,
+ "int": {
+ "ip": 281473913979171,
+ "network": 281473913979171,
+ "broadcast": 281473913979171,
+ "first_host": 281473913979171,
+ "last_host": 281473913979171
+ },
+ "hex": {
+ "ip": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "network": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "broadcast": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "first_host": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23",
+ "last_host": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23"
+ },
+ "bin": {
+ "ip": "0000000000000000000000000000000000000000000000000000000...",
+ "network": "00000000000000000000000000000000000000000000000000...",
+ "broadcast": "000000000000000000000000000000000000000000000000...",
+ "hostmask": "0000000000000000000000000000000000000000000000000...",
+ "netmask": "11111111111111111111111111111111111111111111111111...",
+ "first_host": "00000000000000000000000000000000000000000000000...",
+ "last_host": "000000000000000000000000000000000000000000000000..."
+ }
+ }
+
+ # 6to4 Address
+ $ echo 2002:c000:204::/48 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "2002:c000:204::",
+ "ip_compressed": "2002:c000:204::/48",
+ "ip_exploded": "2002:c000:0204:0000:0000:0000:0000:0000/48",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": "192.0.2.4",
+ "teredo_client": null,
+ "teredo_server": null,
+ "dns_ptr": "0.0.0.0.0.0.0.0......0.4.0.2.0.0.0.0.c.2.0.0.2.ip6.arpa",
+ "network": "2002:c000:204::",
+ "broadcast": "2002:c000:204:ffff:ffff:ffff:ffff:ffff",
+ "hostmask": "::ffff:ffff:ffff:ffff:ffff",
+ "netmask": "ffff:ffff:ffff::",
+ "cidr_netmask": 48,
+ "hosts": 1208925819614629174706174,
+ "first_host": "2002:c000:204::1",
+ "last_host": "2002:c000:204:ffff:ffff:ffff:ffff:fffe",
+ "is_multicast": false,
+ "is_private": false,
+ "is_global": true,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 42549574682102084431821433448024768512,
+ "network": 42549574682102084431821433448024768512,
+ "broadcast": 42549574682103293357641048077199474687,
+ "first_host": 42549574682102084431821433448024768513,
+ "last_host": 42549574682103293357641048077199474686
+ },
+ "hex": {
+ "ip": "20:02:c0:00:02:04:00:00:00:00:00:00:00:00:00:00",
+ "network": "20:02:c0:00:02:04:00:00:00:00:00:00:00:00:00:00",
+ "broadcast": "20:02:c0:00:02:04:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "hostmask": "00:00:00:00:00:00:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "netmask": "ff:ff:ff:ff:ff:ff:00:00:00:00:00:00:00:00:00:00",
+ "first_host": "20:02:c0:00:02:04:00:00:00:00:00:00:00:00:00:01",
+ "last_host": "20:02:c0:00:02:04:ff:ff:ff:ff:ff:ff:ff:ff:ff:fe"
+ },
+ "bin": {
+ "ip": "0010000000000010110000000000000000000010000001000000000...",
+ "network": "00100000000000101100000000000000000000100000010000...",
+ "broadcast": "001000000000001011000000000000000000001000000100...",
+ "hostmask": "0000000000000000000000000000000000000000000000001...",
+ "netmask": "11111111111111111111111111111111111111111111111100...",
+ "first_host": "00100000000000101100000000000000000000100000010...",
+ "last_host": "001000000000001011000000000000000000001000000100..."
+ }
+ }
+
+ # Teredo Address
+ % echo 2001:0000:4136:e378:8000:63bf:3fff:fdd2 | jc --ip-address -p
+ {
+ "version": 6,
+ "max_prefix_length": 128,
+ "ip": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "ip_compressed": "2001:0:4136:e378:8000:63bf:3fff:fdd2/128",
+ "ip_exploded": "2001:0000:4136:e378:8000:63bf:3fff:fdd2/128",
+ "scope_id": null,
+ "ipv4_mapped": null,
+ "six_to_four": null,
+ "teredo_client": "192.0.2.45",
+ "teredo_server": "65.54.227.120",
+ "dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0....0.0.0.1.0.0.2.ip6.arpa",
+ "network": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "broadcast": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "hostmask": "::",
+ "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+ "cidr_netmask": 128,
+ "hosts": 1,
+ "first_host": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "last_host": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
+ "is_multicast": false,
+ "is_private": true,
+ "is_global": false,
+ "is_link_local": false,
+ "is_loopback": false,
+ "is_reserved": false,
+ "is_unspecified": false,
+ "int": {
+ "ip": 42540488182158724593221357832373272018,
+ "network": 42540488182158724593221357832373272018,
+ "broadcast": 42540488182158724593221357832373272018,
+ "first_host": 42540488182158724593221357832373272018,
+ "last_host": 42540488182158724593221357832373272018
+ },
+ "hex": {
+ "ip": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "network": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "broadcast": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "hostmask": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
+ "netmask": "ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff",
+ "first_host": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2",
+ "last_host": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2"
+ },
+ "bin": {
+ "ip": "001000000000000100000000000000000100000100110110111000...",
+ "network": "0010000000000001000000000000000001000001001101101...",
+ "broadcast": "00100000000000010000000000000000010000010011011...",
+ "hostmask": "000000000000000000000000000000000000000000000000...",
+ "netmask": "1111111111111111111111111111111111111111111111111...",
+ "first_host": "0010000000000001000000000000000001000001001101...",
+ "last_host": "00100000000000010000000000000000010000010011011..."
+ }
+ }
"""
from typing import Dict
import binascii
@@ -97,7 +529,13 @@ def parse(
if jc.utils.has_data(data):
- interface = ipaddress.ip_interface(data.strip())
+ # Accept IPs entered as integer notation
+ try:
+ data = int(data) # type: ignore
+ except Exception:
+ data = data.strip()
+
+ interface = ipaddress.ip_interface(data)
network_string = str(interface.network).split('/')[0]
network_cidr = int(str(interface.with_prefixlen).split('/')[1])
network = ipaddress.ip_network(f'{network_string}/{network_cidr}')
@@ -170,6 +608,13 @@ def parse(
'is_loopback': interface.is_loopback,
'is_reserved': interface.is_reserved,
'is_unspecified': interface.is_unspecified,
+ 'int': {
+ 'ip': int(interface),
+ 'network': int(ipaddress.ip_address(network_string)),
+ 'broadcast': int(ipaddress.ip_address(broadcast_string)),
+ 'first_host': int(ipaddress.ip_address(first_host)),
+ 'last_host': int(ipaddress.ip_address(last_host))
+ },
'hex': {
'ip': _b2a(bare_ip.packed),
'network': _b2a(ipaddress.ip_address(network_string).packed),
diff --git a/man/jc.1 b/man/jc.1
index 60b8b8a1..7bd6e705 100644
--- a/man/jc.1
+++ b/man/jc.1
@@ -1,4 +1,4 @@
-.TH jc 1 2022-07-23 1.20.4 "JSON Convert"
+.TH jc 1 2022-07-27 1.20.5 "JSON Convert"
.SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools and file-types
.SH SYNOPSIS
@@ -222,6 +222,11 @@ INI file parser
\fB--iostat-s\fP
`iostat` command streaming parser
+.TP
+.B
+\fB--ip-address\fP
+IP Address string parser
+
.TP
.B
\fB--iptables\fP