mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add support for error replies in v4 ping on osx and bsd
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
jc changelog
|
||||
|
||||
20210510 v1.15.4
|
||||
- Update ping parser to support error responses in OSX and BSD
|
||||
|
||||
20210426 v1.15.3
|
||||
- Add ufw status command parser tested on linux
|
||||
- Add ufw-appinfo command parser tested on linux
|
||||
|
@ -157,7 +157,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
version = '1.5'
|
||||
description = '`ping` and `ping6` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -496,10 +496,15 @@ def _bsd_parse(data):
|
||||
err = _error_type(line)
|
||||
if err:
|
||||
response = {
|
||||
'type': err,
|
||||
'bytes': line.split()[0],
|
||||
'response_ip': line.split()[4].strip(':').strip('(').strip(')'),
|
||||
'type': err
|
||||
}
|
||||
|
||||
try:
|
||||
response['bytes'] = line.split()[0]
|
||||
response['response_ip'] = line.split()[4].strip(':').strip('(').strip(')')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
ping_error = True
|
||||
continue
|
||||
|
||||
@ -508,9 +513,11 @@ def _bsd_parse(data):
|
||||
continue
|
||||
else:
|
||||
error_line = line.split()
|
||||
|
||||
try:
|
||||
response.update(
|
||||
{
|
||||
'vr': int(error_line[0], 16),
|
||||
'vr': int(error_line[0], 16), # convert from hex to decimal
|
||||
'hl': int(error_line[1], 16),
|
||||
'tos': int(error_line[2], 16),
|
||||
'len': int(error_line[3], 16),
|
||||
@ -524,8 +531,13 @@ def _bsd_parse(data):
|
||||
'dst': error_line[11],
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if response:
|
||||
ping_responses.append(response)
|
||||
error_line = False
|
||||
|
||||
ping_error = False
|
||||
continue
|
||||
|
||||
# normal response
|
||||
|
1
tests/fixtures/osx-10.14.6/ping-ip-unreachable.json
vendored
Normal file
1
tests/fixtures/osx-10.14.6/ping-ip-unreachable.json
vendored
Normal file
@ -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":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":22139,"flg":0,"off":0,"ttl":63,"pro":1,"cks":40996,"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":11887,"flg":0,"off":0,"ttl":63,"pro":1,"cks":51248,"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":41453,"flg":0,"off":0,"ttl":63,"pro":1,"cks":21682,"src":"192.168.1.221","dst":"192.168.1.220"},{"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}]}
|
35
tests/fixtures/osx-10.14.6/ping-ip-unreachable.out
vendored
Normal file
35
tests/fixtures/osx-10.14.6/ping-ip-unreachable.out
vendored
Normal file
@ -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 Host 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): Destination Host Unreachable
|
||||
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
|
@ -157,6 +157,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping_ip = f.read()
|
||||
|
||||
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/ping6-hostname-p.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping6_hostname_p = f.read()
|
||||
|
||||
@ -336,6 +339,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping_ip_json = json.loads(f.read())
|
||||
|
||||
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/ping6-hostname-p.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping6_hostname_p_json = json.loads(f.read())
|
||||
|
||||
@ -651,10 +657,16 @@ class MyTests(unittest.TestCase):
|
||||
|
||||
def test_ping_ip_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'ping6 <ip>' on osx 10.14.6
|
||||
Test 'ping <ip>' on osx 10.14.6
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ping.parse(self.osx_10_14_6_ping_ip, quiet=True), self.osx_10_14_6_ping_ip_json)
|
||||
|
||||
def test_ping_ip_unreachable_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'ping <ip>' with host unreachable error on osx 10.14.6
|
||||
"""
|
||||
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_ping6_hostname_p_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'ping6 <hostname> -p' on osx 10.14.6
|
||||
|
Reference in New Issue
Block a user