4

I want to send echo request with ICMP and python's socket. I was sending packet. But my program is hang up on recv from socket. Why my socket is hang up? OS is Windows10. Launch terminal is admin mode.

# -*- coding: utf-8 -*-
import socket
import struct


def ping(host, port):
    with socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP) as sock:
        sock.connect((host, port))
        sock.settimeout(30)
        icmp_message = struct.pack('!BBHHH', 8, 0, 8, 0, 0)
        packet = icmp_message
        print('send packet...')
        sock.sendall(packet)
        print('recv...')
        data = sock.recv(1024)


def main():
    ping('192.168.0.1', 80)


if __name__ == '__main__':
    main()
arai
  • 1,251
  • 2
  • 12
  • 17

0 Answers0