Socket Programming in Python

2025-08-25

Socket packet in python is a lower level network tool.

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                 socket.IPPROTO_ICMP)

socket.AF_INET means ipv4, and socket.SOCK_DGRAM means UDP. The last argument socket.IPPROTO_ICMP means adding the icmp on the top.