diff --git a/jc/parsers/ping.py b/jc/parsers/ping.py index c07a2b82..a1a5f035 100644 --- a/jc/parsers/ping.py +++ b/jc/parsers/ping.py @@ -364,7 +364,7 @@ def _linux_parse(data): continue # normal responses - else: + elif ' bytes from ' in line: try: line = line.replace('(', ' ').replace(')', ' ').replace('=', ' ') @@ -547,9 +547,10 @@ def _bsd_parse(data): continue # normal response - else: + elif ' bytes from ' in line: try: line = line.replace(':', ' ').replace('=', ' ') + response = { 'type': 'reply', 'bytes': line.split()[0], @@ -568,7 +569,7 @@ def _bsd_parse(data): continue # ipv6 lines - else: + elif ' bytes from ' in line: try: line = line.replace(',', ' ').replace('=', ' ') response = { diff --git a/tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json b/tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json new file mode 100644 index 00000000..02cc13ea --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json @@ -0,0 +1 @@ +{"destination_ip":"192.168.1.220","data_bytes":56,"pattern":null,"destination":"192.168.1.220","packets_transmitted":8,"packets_received":0,"packet_loss_percent":100.0,"duplicates":0,"responses":[{"type":"timeout","icmp_seq":0,"duplicate":false},{"type":"timeout","icmp_seq":1,"duplicate":false},{"type":"unparsable_line","unparsed_line":"92 bytes from fgt1.attlocal.net (192.168.1.220) Destination Network Unreachable"},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":11887,"flg":0,"off":0,"ttl":63,"pro":1,"cks":51248,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"unparsable_line","unparsed_line":"92 bytes from fgt1.attlocal.net (192.168.1.220) Weird error message"},{"type":"timeout","icmp_seq":2,"duplicate":false},{"type":"timeout","icmp_seq":3,"duplicate":false},{"type":"timeout","icmp_seq":4,"duplicate":false},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":40674,"flg":0,"off":0,"ttl":63,"pro":1,"cks":22461,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":31035,"flg":0,"off":0,"ttl":63,"pro":1,"cks":32100,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":53536,"flg":0,"off":0,"ttl":63,"pro":1,"cks":9599,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"timeout","icmp_seq":5,"duplicate":false},{"type":"timeout","icmp_seq":6,"duplicate":false}]} diff --git a/tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out b/tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out new file mode 100644 index 00000000..1d6b41d7 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out @@ -0,0 +1,35 @@ +PING 192.168.1.220 (192.168.1.220): 56 data bytes +Request timeout for icmp_seq 0 +Request timeout for icmp_seq 1 +92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Network Unreachable +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 5400 567b 0 0000 3f 01 a024 192.168.1.221 192.168.1.220 + +92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 5400 2e6f 0 0000 3f 01 c830 192.168.1.221 192.168.1.220 + +92 bytes from fgt1.attlocal.net (192.168.1.220): Weird error message +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 5400 a1ed 0 0000 3f 01 54b2 192.168.1.221 192.168.1.220 + +Request timeout for icmp_seq 2 +Request timeout for icmp_seq 3 +Request timeout for icmp_seq 4 +92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 5400 9ee2 0 0000 3f 01 57bd 192.168.1.221 192.168.1.220 + +92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 5400 793b 0 0000 3f 01 7d64 192.168.1.221 192.168.1.220 + +92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 5400 d120 0 0000 3f 01 257f 192.168.1.221 192.168.1.220 + +Request timeout for icmp_seq 5 +Request timeout for icmp_seq 6 + +--- 192.168.1.220 ping statistics --- +8 packets transmitted, 0 packets received, 100.0% packet loss diff --git a/tests/test_ping.py b/tests/test_ping.py index be903337..f04dadb4 100644 --- a/tests/test_ping.py +++ b/tests/test_ping.py @@ -160,6 +160,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unreachable.out'), 'r', encoding='utf-8') as f: self.osx_10_14_6_ping_ip_unreachable = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_ping_ip_unknown_errors = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping6-hostname-p.out'), 'r', encoding='utf-8') as f: self.osx_10_14_6_ping6_hostname_p = f.read() @@ -342,6 +345,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unreachable.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_ping_ip_unreachable_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_ping_ip_unknown_errors_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping6-hostname-p.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_ping6_hostname_p_json = json.loads(f.read()) @@ -667,6 +673,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.ping.parse(self.osx_10_14_6_ping_ip_unreachable, quiet=True), self.osx_10_14_6_ping_ip_unreachable_json) + def test_ping_ip_unknown_errors_osx_10_14_6(self): + """ + Test 'ping ' with unknown/unparsable errors on osx 10.14.6 + """ + self.assertEqual(jc.parsers.ping.parse(self.osx_10_14_6_ping_ip_unknown_errors, quiet=True), self.osx_10_14_6_ping_ip_unknown_errors_json) + def test_ping6_hostname_p_osx_10_14_6(self): """ Test 'ping6 -p' on osx 10.14.6