Created
August 12, 2019 05:25
-
-
Save Matts966/26c9f717c12f2d85a74e63f478371180 to your computer and use it in GitHub Desktop.
Listen broadcast udp packet.
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
from socket import * | |
import sys | |
if len(sys.argv) != 2: | |
print("Please give me port number.") | |
else: | |
try: | |
port=int(sys.argv[1]) | |
except ValueError: | |
print('Invalid port number.') | |
sys.exit(1) | |
try: | |
s = socket(AF_INET, SOCK_DGRAM) | |
s.bind(('', port)) | |
while True: | |
data, address = s.recvfrom(1024) | |
print((data.decode('utf-8').rstrip())) | |
except Exception as e: | |
s.close() | |
print(e.args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment