(payload: bytes)
| 155 | |
| 156 | |
| 157 | def build_icmp(payload: bytes) -> bytes: |
| 158 | # Define the ICMP Echo Request packet |
| 159 | icmp_packet = struct.pack('!BBHHH', 8, 0, 0, 0, 1) + payload |
| 160 | |
| 161 | checksum = calc_checksum(icmp_packet) |
| 162 | |
| 163 | return struct.pack('!BBHHH', 8, 0, checksum, 0, 1) + payload |
| 164 | |
| 165 | |
| 166 | def ping(hostname: str, timeout: int = 5) -> int: |