diff --git a/CHANGELOG b/CHANGELOG index ed6a0418..d4108573 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ jc changelog 20221004 v1.22.1 - fix `proc-pid-stat` parser for command names with spaces and newlines +- enhance `ip-address` parser to add `ip_split` field - rename `iso-datetime` parser to `datetime-iso`. A deprecation warning will display until `iso-datetime` is removed in a future version. - refactor cli module diff --git a/docs/parsers/datetime_iso.md b/docs/parsers/datetime_iso.md new file mode 100644 index 00000000..e99b9d7a --- /dev/null +++ b/docs/parsers/datetime_iso.md @@ -0,0 +1,91 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.datetime\_iso + +jc - JSON Convert ISO 8601 Datetime string parser + +This parser supports standard ISO 8601 strings that include both date and +time. If no timezone or offset information is available in the sring, then +UTC timezone is used. + +Usage (cli): + + $ echo "2022-07-20T14:52:45Z" | jc --iso-datetime + +Usage (module): + + import jc + result = jc.parse('iso_datetime', iso_8601_string) + +Schema: + + { + "year": integer, + "month": string, + "month_num": integer, + "day": integer, + "weekday": string, + "weekday_num": integer, + "hour": integer, + "hour_24": integer, + "minute": integer, + "second": integer, + "microsecond": integer, + "period": string, + "utc_offset": string, + "day_of_year": integer, + "week_of_year": integer, + "iso": string, + "timestamp": integer # [0] + } + + [0] timezone aware UNIX timestamp expressed in UTC + +Examples: + + $ echo "2022-07-20T14:52:45Z" | jc --iso-datetime -p + { + "year": 2022, + "month": "Jul", + "month_num": 7, + "day": 20, + "weekday": "Wed", + "weekday_num": 3, + "hour": 2, + "hour_24": 14, + "minute": 52, + "second": 45, + "microsecond": 0, + "period": "PM", + "utc_offset": "+0000", + "day_of_year": 201, + "week_of_year": 29, + "iso": "2022-07-20T14:52:45+00:00", + "timestamp": 1658328765 + } + + + +### parse + +```python +def parse(data, raw=False, quiet=False) +``` + +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, aix, freebsd, darwin, win32, cygwin + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/ip_address.md b/docs/parsers/ip_address.md index de07d035..cd27fd61 100644 --- a/docs/parsers/ip_address.md +++ b/docs/parsers/ip_address.md @@ -26,6 +26,9 @@ Schema: "ip": string, "ip_compressed": string, "ip_exploded": string, + "ip_split": [ + string + ], "scope_id": string/null, "ipv4_mapped": string/null, "six_to_four": string/null, @@ -83,6 +86,12 @@ Examples: "ip": "192.168.2.10", "ip_compressed": "192.168.2.10", "ip_exploded": "192.168.2.10", + "ip_split": [ + "192", + "168", + "2", + "10" + ], "scope_id": null, "ipv4_mapped": null, "six_to_four": null, @@ -138,6 +147,12 @@ Examples: "ip": "192.168.2.10", "ip_compressed": "192.168.2.10", "ip_exploded": "192.168.2.10", + "ip_split": [ + "192", + "168", + "2", + "10" + ], "scope_id": null, "ipv4_mapped": null, "six_to_four": null, @@ -191,14 +206,24 @@ Examples: "version": 6, "max_prefix_length": 128, "ip": "127:0:de::1", - "ip_compressed": "127:0:de::1%128", + "ip_compressed": "127:0:de::1", "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001", + "ip_split": [ + "0127", + "0000", + "00de", + "0000", + "0000", + "0000", + "0000", + "0001" + ], "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", + "dns_ptr": "1.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::", "broadcast": "127:0:de::ffff:ffff", "hostmask": "::ffff:ffff", @@ -231,13 +256,13 @@ Examples: "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..." + "ip": "0000000100100111000000000000000000000000110...000000000001", + "network": "00000001001001110000000000000000000000...000000000000", + "broadcast": "000000010010011100000000000000000000...111111111111", + "hostmask": "0000000000000000000000000000000000000...111111111111", + "netmask": "11111111111111111111111111111111111111...000000000000", + "first_host": "00000001001001110000000000000000000...000000000001", + "last_host": "000000010010011100000000000000000000...1111111111110" } } @@ -248,12 +273,22 @@ Examples: "ip": "127:0:de::1", "ip_compressed": "127:0:de::1", "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001", + "ip_split": [ + "0127", + "0000", + "00de", + "0000", + "0000", + "0000", + "0000", + "0001" + ], "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", + "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": "::", @@ -286,13 +321,13 @@ Examples: "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..." + "ip": "0000000100100111000000000000000000000000110111100...000001", + "network": "00000001001001110000000000000000000000001101...000001", + "broadcast": "000000010010011100000000000000000000000011...000001", + "hostmask": "0000000000000000000000000000000000000000000...000000", + "netmask": "11111111111111111111111111111111111111111111...111111", + "first_host": "00000001001001110000000000000000000000001...000001", + "last_host": "000000010010011100000000000000000000000011...0000001" } } @@ -304,12 +339,22 @@ Examples: "ip": "::ffff:c0a8:123", "ip_compressed": "::ffff:c0a8:123", "ip_exploded": "0000:0000:0000:0000:0000:ffff:c0a8:0123", + "ip_split": [ + "0000", + "0000", + "0000", + "0000", + "0000", + "ffff", + "c0a8", + "0123" + ], "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", + "dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0....0.0.0.0.0.0.ip6.arpa", "network": "::ffff:c0a8:123", "broadcast": "::ffff:c0a8:123", "hostmask": "::", @@ -342,13 +387,13 @@ Examples: "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..." + "ip": "000000000000000000000000000000000000000000000...100100011", + "network": "0000000000000000000000000000000000000000...000100011", + "broadcast": "00000000000000000000000000000000000000...000100011", + "hostmask": "000000000000000000000000000000000000000...000000000", + "netmask": "1111111111111111111111111111111111111111...111111111", + "first_host": "0000000000000000000000000000000000000...100100011", + "last_host": "00000000000000000000000000000000000000...0100100011" } } @@ -360,12 +405,22 @@ Examples: "ip": "2002:c000:204::", "ip_compressed": "2002:c000:204::", "ip_exploded": "2002:c000:0204:0000:0000:0000:0000:0000", + "ip_split": [ + "2002", + "c000", + "0204", + "0000", + "0000", + "0000", + "0000", + "0000" + ], "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", + "dns_ptr": "0.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", @@ -398,13 +453,13 @@ Examples: "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..." + "ip": "00100000000000101100000000000000000000100000010...00000000", + "network": "001000000000001011000000000000000000001000...00000000", + "broadcast": "0010000000000010110000000000000000000010...11111111", + "hostmask": "00000000000000000000000000000000000000000...11111111", + "netmask": "111111111111111111111111111111111111111111...00000000", + "first_host": "001000000000001011000000000000000000001...00000001", + "last_host": "0010000000000010110000000000000000000010...111111110" } } @@ -416,12 +471,22 @@ Examples: "ip": "2001:0:4136:e378:8000:63bf:3fff:fdd2", "ip_compressed": "2001:0:4136:e378:8000:63bf:3fff:fdd2", "ip_exploded": "2001:0000:4136:e378:8000:63bf:3fff:fdd2", + "ip_split": [ + "2001", + "0000", + "4136", + "e378", + "8000", + "63bf", + "3fff", + "fdd2" + ], "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", + "dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0.8.8....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": "::", @@ -454,13 +519,13 @@ Examples: "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..." + "ip": "0010000000000001000000000000000001000001001...110111010010", + "network": "00100000000000010000000000000000010000...110111010010", + "broadcast": "001000000000000100000000000000000100...110111010010", + "hostmask": "0000000000000000000000000000000000000...000000000000", + "netmask": "11111111111111111111111111111111111111...111111111111", + "first_host": "00100000000000010000000000000000010...110111010010", + "last_host": "001000000000000100000000000000000100...110111010010" } } @@ -487,4 +552,4 @@ Returns: ### Parser Information Compatibility: linux, darwin, cygwin, win32, aix, freebsd -Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/parsers/ip_address.py b/jc/parsers/ip_address.py index fc9a0939..5610d142 100644 --- a/jc/parsers/ip_address.py +++ b/jc/parsers/ip_address.py @@ -21,6 +21,9 @@ Schema: "ip": string, "ip_compressed": string, "ip_exploded": string, + "ip_split": [ + string + ], "scope_id": string/null, "ipv4_mapped": string/null, "six_to_four": string/null, @@ -78,6 +81,12 @@ Examples: "ip": "192.168.2.10", "ip_compressed": "192.168.2.10", "ip_exploded": "192.168.2.10", + "ip_split": [ + "192", + "168", + "2", + "10" + ], "scope_id": null, "ipv4_mapped": null, "six_to_four": null, @@ -133,6 +142,12 @@ Examples: "ip": "192.168.2.10", "ip_compressed": "192.168.2.10", "ip_exploded": "192.168.2.10", + "ip_split": [ + "192", + "168", + "2", + "10" + ], "scope_id": null, "ipv4_mapped": null, "six_to_four": null, @@ -186,14 +201,24 @@ Examples: "version": 6, "max_prefix_length": 128, "ip": "127:0:de::1", - "ip_compressed": "127:0:de::1%128", + "ip_compressed": "127:0:de::1", "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001", + "ip_split": [ + "0127", + "0000", + "00de", + "0000", + "0000", + "0000", + "0000", + "0001" + ], "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", + "dns_ptr": "1.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::", "broadcast": "127:0:de::ffff:ffff", "hostmask": "::ffff:ffff", @@ -226,13 +251,13 @@ Examples: "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..." + "ip": "0000000100100111000000000000000000000000110...000000000001", + "network": "00000001001001110000000000000000000000...000000000000", + "broadcast": "000000010010011100000000000000000000...111111111111", + "hostmask": "0000000000000000000000000000000000000...111111111111", + "netmask": "11111111111111111111111111111111111111...000000000000", + "first_host": "00000001001001110000000000000000000...000000000001", + "last_host": "000000010010011100000000000000000000...1111111111110" } } @@ -243,12 +268,22 @@ Examples: "ip": "127:0:de::1", "ip_compressed": "127:0:de::1", "ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001", + "ip_split": [ + "0127", + "0000", + "00de", + "0000", + "0000", + "0000", + "0000", + "0001" + ], "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", + "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": "::", @@ -281,13 +316,13 @@ Examples: "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..." + "ip": "0000000100100111000000000000000000000000110111100...000001", + "network": "00000001001001110000000000000000000000001101...000001", + "broadcast": "000000010010011100000000000000000000000011...000001", + "hostmask": "0000000000000000000000000000000000000000000...000000", + "netmask": "11111111111111111111111111111111111111111111...111111", + "first_host": "00000001001001110000000000000000000000001...000001", + "last_host": "000000010010011100000000000000000000000011...0000001" } } @@ -299,12 +334,22 @@ Examples: "ip": "::ffff:c0a8:123", "ip_compressed": "::ffff:c0a8:123", "ip_exploded": "0000:0000:0000:0000:0000:ffff:c0a8:0123", + "ip_split": [ + "0000", + "0000", + "0000", + "0000", + "0000", + "ffff", + "c0a8", + "0123" + ], "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", + "dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0....0.0.0.0.0.0.ip6.arpa", "network": "::ffff:c0a8:123", "broadcast": "::ffff:c0a8:123", "hostmask": "::", @@ -337,13 +382,13 @@ Examples: "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..." + "ip": "000000000000000000000000000000000000000000000...100100011", + "network": "0000000000000000000000000000000000000000...000100011", + "broadcast": "00000000000000000000000000000000000000...000100011", + "hostmask": "000000000000000000000000000000000000000...000000000", + "netmask": "1111111111111111111111111111111111111111...111111111", + "first_host": "0000000000000000000000000000000000000...100100011", + "last_host": "00000000000000000000000000000000000000...0100100011" } } @@ -355,12 +400,22 @@ Examples: "ip": "2002:c000:204::", "ip_compressed": "2002:c000:204::", "ip_exploded": "2002:c000:0204:0000:0000:0000:0000:0000", + "ip_split": [ + "2002", + "c000", + "0204", + "0000", + "0000", + "0000", + "0000", + "0000" + ], "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", + "dns_ptr": "0.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", @@ -393,13 +448,13 @@ Examples: "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..." + "ip": "00100000000000101100000000000000000000100000010...00000000", + "network": "001000000000001011000000000000000000001000...00000000", + "broadcast": "0010000000000010110000000000000000000010...11111111", + "hostmask": "00000000000000000000000000000000000000000...11111111", + "netmask": "111111111111111111111111111111111111111111...00000000", + "first_host": "001000000000001011000000000000000000001...00000001", + "last_host": "0010000000000010110000000000000000000010...111111110" } } @@ -411,12 +466,22 @@ Examples: "ip": "2001:0:4136:e378:8000:63bf:3fff:fdd2", "ip_compressed": "2001:0:4136:e378:8000:63bf:3fff:fdd2", "ip_exploded": "2001:0000:4136:e378:8000:63bf:3fff:fdd2", + "ip_split": [ + "2001", + "0000", + "4136", + "e378", + "8000", + "63bf", + "3fff", + "fdd2" + ], "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", + "dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0.8.8....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": "::", @@ -449,13 +514,13 @@ Examples: "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..." + "ip": "0010000000000001000000000000000001000001001...110111010010", + "network": "00100000000000010000000000000000010000...110111010010", + "broadcast": "001000000000000100000000000000000100...110111010010", + "hostmask": "0000000000000000000000000000000000000...000000000000", + "netmask": "11111111111111111111111111111111111111...111111111111", + "first_host": "00100000000000010000000000000000010...110111010010", + "last_host": "001000000000000100000000000000000100...110111010010" } } """ @@ -468,7 +533,7 @@ import jc.utils class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.2' + version = '1.3' description = 'IPv4 and IPv6 Address string parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -590,6 +655,13 @@ def parse( bare_ip_string = str(interface.ip) bare_ip = ipaddress.ip_address(bare_ip_string) ip_ptr = bare_ip.reverse_pointer + ip_compressed = bare_ip.compressed + ip_exploded = bare_ip.exploded + + if interface.version == 4: + ip_split = ip_exploded.split('.') + else: + ip_split = ip_exploded.split(':') # fix for ipv6-only attributes scope_id = None @@ -638,8 +710,9 @@ def parse( 'version': interface.version, 'max_prefix_length': interface.max_prefixlen, 'ip': bare_ip_string, - 'ip_compressed': bare_ip.compressed, - 'ip_exploded': bare_ip.exploded, + 'ip_compressed': ip_compressed, + 'ip_exploded': ip_exploded, + 'ip_split': ip_split, 'scope_id': scope_id, 'ipv4_mapped': ipv4_mapped, 'six_to_four': sixtofour, diff --git a/man/jc.1 b/man/jc.1 index f5e91a98..27847b10 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-10-09 1.22.1 "JSON Convert" +.TH jc 1 2022-10-10 1.22.1 "JSON Convert" .SH NAME \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings .SH SYNOPSIS diff --git a/tests/test_ip_address.py b/tests/test_ip_address.py index e2e1fafe..8c24d882 100644 --- a/tests/test_ip_address.py +++ b/tests/test_ip_address.py @@ -17,7 +17,7 @@ class MyTests(unittest.TestCase): Test ipv4 address string """ data = r'192.168.1.35' - expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.1.35","ip_compressed":"192.168.1.35","ip_exploded":"192.168.1.35","scope_id":null,"ipv4_mapped":null,"six_to_four":null,"teredo_client":null,"teredo_server":null,"dns_ptr":"35.1.168.192.in-addr.arpa","network":"192.168.1.35","broadcast":"192.168.1.35","hostmask":"0.0.0.0","netmask":"255.255.255.255","cidr_netmask":32,"hosts":1,"first_host":"192.168.1.35","last_host":"192.168.1.35","is_multicast":false,"is_private":true,"is_global":false,"is_link_local":false,"is_loopback":false,"is_reserved":false,"is_unspecified":false,"int":{"ip":3232235811,"network":3232235811,"broadcast":3232235811,"first_host":3232235811,"last_host":3232235811},"hex":{"ip":"c0:a8:01:23","network":"c0:a8:01:23","broadcast":"c0:a8:01:23","hostmask":"00:00:00:00","netmask":"ff:ff:ff:ff","first_host":"c0:a8:01:23","last_host":"c0:a8:01:23"},"bin":{"ip":"11000000101010000000000100100011","network":"11000000101010000000000100100011","broadcast":"11000000101010000000000100100011","hostmask":"00000000000000000000000000000000","netmask":"11111111111111111111111111111111","first_host":"11000000101010000000000100100011","last_host":"11000000101010000000000100100011"}}''') + expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.1.35","ip_compressed":"192.168.1.35","ip_exploded":"192.168.1.35","ip_split":["192","168","1","35"],"scope_id":null,"ipv4_mapped":null,"six_to_four":null,"teredo_client":null,"teredo_server":null,"dns_ptr":"35.1.168.192.in-addr.arpa","network":"192.168.1.35","broadcast":"192.168.1.35","hostmask":"0.0.0.0","netmask":"255.255.255.255","cidr_netmask":32,"hosts":1,"first_host":"192.168.1.35","last_host":"192.168.1.35","is_multicast":false,"is_private":true,"is_global":false,"is_link_local":false,"is_loopback":false,"is_reserved":false,"is_unspecified":false,"int":{"ip":3232235811,"network":3232235811,"broadcast":3232235811,"first_host":3232235811,"last_host":3232235811},"hex":{"ip":"c0:a8:01:23","network":"c0:a8:01:23","broadcast":"c0:a8:01:23","hostmask":"00:00:00:00","netmask":"ff:ff:ff:ff","first_host":"c0:a8:01:23","last_host":"c0:a8:01:23"},"bin":{"ip":"11000000101010000000000100100011","network":"11000000101010000000000100100011","broadcast":"11000000101010000000000100100011","hostmask":"00000000000000000000000000000000","netmask":"11111111111111111111111111111111","first_host":"11000000101010000000000100100011","last_host":"11000000101010000000000100100011"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -26,7 +26,7 @@ class MyTests(unittest.TestCase): Test CIDR ipv4 address string """ data = r'192.168.2.10/24' - expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.2.10","ip_compressed":"192.168.2.10","ip_exploded":"192.168.2.10","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"}}''') + expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.2.10","ip_compressed":"192.168.2.10","ip_exploded":"192.168.2.10","ip_split":["192","168","2","10"],"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"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -35,7 +35,7 @@ class MyTests(unittest.TestCase): Test ipv4 address with a dotted netmask string """ data = r'192.168.0.1/255.255.128.0' - expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.0.1","ip_compressed":"192.168.0.1","ip_exploded":"192.168.0.1","scope_id":null,"ipv4_mapped":null,"six_to_four":null,"teredo_client":null,"teredo_server":null,"dns_ptr":"1.0.168.192.in-addr.arpa","network":"192.168.0.0","broadcast":"192.168.127.255","hostmask":"0.0.127.255","netmask":"255.255.128.0","cidr_netmask":17,"hosts":32766,"first_host":"192.168.0.1","last_host":"192.168.127.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":3232235521,"network":3232235520,"broadcast":3232268287,"first_host":3232235521,"last_host":3232268286},"hex":{"ip":"c0:a8:00:01","network":"c0:a8:00:00","broadcast":"c0:a8:7f:ff","hostmask":"00:00:7f:ff","netmask":"ff:ff:80:00","first_host":"c0:a8:00:01","last_host":"c0:a8:7f:fe"},"bin":{"ip":"11000000101010000000000000000001","network":"11000000101010000000000000000000","broadcast":"11000000101010000111111111111111","hostmask":"00000000000000000111111111111111","netmask":"11111111111111111000000000000000","first_host":"11000000101010000000000000000001","last_host":"11000000101010000111111111111110"}}''') + expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.0.1","ip_compressed":"192.168.0.1","ip_exploded":"192.168.0.1","ip_split":["192","168","0","1"],"scope_id":null,"ipv4_mapped":null,"six_to_four":null,"teredo_client":null,"teredo_server":null,"dns_ptr":"1.0.168.192.in-addr.arpa","network":"192.168.0.0","broadcast":"192.168.127.255","hostmask":"0.0.127.255","netmask":"255.255.128.0","cidr_netmask":17,"hosts":32766,"first_host":"192.168.0.1","last_host":"192.168.127.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":3232235521,"network":3232235520,"broadcast":3232268287,"first_host":3232235521,"last_host":3232268286},"hex":{"ip":"c0:a8:00:01","network":"c0:a8:00:00","broadcast":"c0:a8:7f:ff","hostmask":"00:00:7f:ff","netmask":"ff:ff:80:00","first_host":"c0:a8:00:01","last_host":"c0:a8:7f:fe"},"bin":{"ip":"11000000101010000000000000000001","network":"11000000101010000000000000000000","broadcast":"11000000101010000111111111111111","hostmask":"00000000000000000111111111111111","netmask":"11111111111111111000000000000000","first_host":"11000000101010000000000000000001","last_host":"11000000101010000111111111111110"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -44,7 +44,7 @@ class MyTests(unittest.TestCase): Test ipv4 address integer string """ data = r'3232236042' - expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.2.10","ip_compressed":"192.168.2.10","ip_exploded":"192.168.2.10","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"}}''') + expected = json.loads(r'''{"version":4,"max_prefix_length":32,"ip":"192.168.2.10","ip_compressed":"192.168.2.10","ip_exploded":"192.168.2.10","ip_split":["192","168","2","10"],"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"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -53,7 +53,7 @@ class MyTests(unittest.TestCase): Test ipv6 address string """ data = r'127:0:de::1' - expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","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.0.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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001"}}''') + expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","ip_split":["0127","0000","00de","0000","0000","0000","0000","0001"],"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.0.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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -62,7 +62,7 @@ class MyTests(unittest.TestCase): Test CIDR ipv6 address string """ data = r'127:0:de::1/96' - expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","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.0.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::","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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000000","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111111","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111110"}}''') + expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","ip_split":["0127","0000","00de","0000","0000","0000","0000","0001"],"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.0.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::","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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000000","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111111","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111110"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -71,7 +71,7 @@ class MyTests(unittest.TestCase): Test CIDR ipv6 address with scope string """ data = r'127:0:de::1%128aBc123/96' - expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","scope_id":"128aBc123","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.0.0.0.e.d.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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000000","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111111","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111110"}}''') + expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","ip_split":["0127","0000","00de","0000","0000","0000","0000","0001"],"scope_id":"128aBc123","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.0.0.0.e.d.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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000000","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111111","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000011111111111111111111111111111110"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -80,7 +80,7 @@ class MyTests(unittest.TestCase): Test ipv6 address integer string """ data = r'1531727573536155682370944093904699393' - expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","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.0.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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001"}}''') + expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"127:0:de::1","ip_compressed":"127:0:de::1","ip_exploded":"0127:0000:00de:0000:0000:0000:0000:0001","ip_split":["0127","0000","00de","0000","0000","0000","0000","0001"],"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.0.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":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","network":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","broadcast":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00000001001001110000000000000000000000001101111000000000000000000000000000000000000000000000000000000000000000000000000000000001"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -89,7 +89,7 @@ class MyTests(unittest.TestCase): Test ipv6 address with ipv4 mapped string """ data = r'::FFFF:192.168.1.35' - expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"::ffff:c0a8:123","ip_compressed":"::ffff:c0a8:123","ip_exploded":"0000:0000:0000:0000:0000:ffff:c0a8:0123","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.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":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","network":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","broadcast":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","last_host":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011"}}''') + expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"::ffff:c0a8:123","ip_compressed":"::ffff:c0a8:123","ip_exploded":"0000:0000:0000:0000:0000:ffff:c0a8:0123","ip_split":["0000","0000","0000","0000","0000","ffff","c0a8","0123"],"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.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":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","network":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","broadcast":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011","last_host":"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000101010000000000100100011"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -98,7 +98,7 @@ class MyTests(unittest.TestCase): Test ipv6 6to4 address string """ data = r'2002:c000:204::/48' - expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"2002:c000:204::","ip_compressed":"2002:c000:204::","ip_exploded":"2002:c000:0204:0000:0000:0000:0000:0000","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.0.0.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":"00100000000000101100000000000000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000000","network":"00100000000000101100000000000000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000000","broadcast":"00100000000000101100000000000000000000100000010011111111111111111111111111111111111111111111111111111111111111111111111111111111","hostmask":"00000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111","netmask":"11111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000","first_host":"00100000000000101100000000000000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00100000000000101100000000000000000000100000010011111111111111111111111111111111111111111111111111111111111111111111111111111110"}}''') + expected = json.loads(r'''{"version":6,"max_prefix_length":128,"ip":"2002:c000:204::","ip_compressed":"2002:c000:204::","ip_exploded":"2002:c000:0204:0000:0000:0000:0000:0000","ip_split":["2002","c000","0204","0000","0000","0000","0000","0000"],"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.0.0.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":"00100000000000101100000000000000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000000","network":"00100000000000101100000000000000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000000","broadcast":"00100000000000101100000000000000000000100000010011111111111111111111111111111111111111111111111111111111111111111111111111111111","hostmask":"00000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111","netmask":"11111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000","first_host":"00100000000000101100000000000000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000001","last_host":"00100000000000101100000000000000000000100000010011111111111111111111111111111111111111111111111111111111111111111111111111111110"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected) @@ -107,7 +107,7 @@ class MyTests(unittest.TestCase): Test ipv6 teredo address string """ data = r'2001:0000:4136:e378:8000:63bf:3fff:fdd2' - expected = json.loads(r'''{"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","ip_exploded":"2001:0000:4136:e378:8000:63bf:3fff:fdd2","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.8.8.7.3.e.6.3.1.4.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":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","network":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","broadcast":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","last_host":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010"}}''') + expected = json.loads(r'''{"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","ip_exploded":"2001:0000:4136:e378:8000:63bf:3fff:fdd2","ip_split":["2001","0000","4136","e378","8000","63bf","3fff","fdd2"],"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.8.8.7.3.e.6.3.1.4.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":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","network":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","broadcast":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","hostmask":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","netmask":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","first_host":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010","last_host":"00100000000000010000000000000000010000010011011011100011011110001000000000000000011000111011111100111111111111111111110111010010"}}''') self.assertEqual(jc.parsers.ip_address.parse(data, quiet=True), expected)