Created
January 29, 2014 09:15
-
-
Save olavmrk/8684342 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import select | |
import socket | |
import struct | |
import sys | |
TIMEOUT = 10.0 | |
ip = sys.argv[1] | |
port = int(sys.argv[2]) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
sock.bind(('', port)) | |
mreq = struct.pack('4sI', socket.inet_aton(ip), socket.INADDR_ANY) | |
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) | |
ready = select.select([sock], [], [], TIMEOUT) | |
if ready[0]: | |
exit(0) | |
else: | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment