Created
April 19, 2017 04:03
-
-
Save mallendeo/62446f18c87e14035039b8d2b69edbb2 to your computer and use it in GitHub Desktop.
UDP dgram python
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
#!/usr/local/bin/python | |
import socket | |
import webbrowser | |
import re | |
import netifaces | |
UDP_IP = netifaces.ifaddresses('en0')[netifaces.AF_INET][0]['broadcast'] | |
UDP_PORT = 48735 | |
sock = socket.socket(socket.AF_INET, # Internet | |
socket.SOCK_DGRAM) # UDP | |
sock.bind((UDP_IP, UDP_PORT)) | |
print 'Broadcast IP: ' + UDP_IP | |
serverIp = False | |
while serverIp == False: | |
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes | |
# Get ip address from udp broadcast | |
regex = r"data:(.+)" | |
matches = re.search(regex, data) | |
serverIp = matches.group(1) | |
print serverIp | |
url = 'http://' + serverIp | |
webbrowser.open(url, new = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment