- icmp_request = (Ether(src=src_mac, dst=dst_mac) /
- IP(src=src_ip, dst=dst_ip) /
- ICMP())
+ if valid_ipv4(src_ip) and valid_ipv4(dst_ip):
+ icmp_request = (Ether(src=src_mac, dst=dst_mac) /
+ IP(src=src_ip, dst=dst_ip) /
+ ICMP())
+ ip_format = {'IPType': 'IP', 'ICMP_req': 'ICMP',
+ 'ICMP_rep': 'ICMP', 'Type': 0}
+ elif valid_ipv6(src_ip) and valid_ipv6(dst_ip):
+ icmp_request = (Ether(src=src_mac, dst=dst_mac) /
+ IPv6(src=src_ip, dst=dst_ip) /
+ ICMPv6EchoRequest())
+ ip_format = {'IPType': 'IPv6', 'ICMP_req': 'ICMPv6 Echo Request',
+ 'ICMP_rep': 'ICMPv6 Echo Reply', 'Type': 129}
+ else:
+ raise ValueError("IP not in correct format")
+