Created
June 8, 2020 08:55
-
-
Save yashshah1/a79b520a10c837397106de37a82dbc40 to your computer and use it in GitHub Desktop.
Basic socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
# DNS runs on port 53 | |
port = 53 | |
# The host for our DNS server is our local host | |
host = '127.0.0.1' | |
# SOCK.AF_INET tells socket to use IPv4 addressing | |
# SOCK.SOCK_DGRAM tells socket to use UDP | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
# This will make our program listen on this host and port. | |
sock.bind((host, port)) | |
# Infinite loop to keep listening on this port. | |
# We reed 512 bytes because that is the maximum | |
# For now we are printing whatever request we get. | |
while True: | |
data, addr = sock.recvfrom(512) | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment