-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSX_broken.py
43 lines (34 loc) · 1.33 KB
/
OSX_broken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
import struct
import socket
import sys
def main():
# Look up multicast group address in name server and find out IP version
addrinfo = socket.getaddrinfo("226.2.2.2", None)[0]
# Create a socket
s = socket.socket(addrinfo[0], socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 2068))
group_bin = socket.inet_pton(addrinfo[0], addrinfo[4][0])
if addrinfo[0] == socket.AF_INET: # IPv4
mreq = socket.inet_aton('226.2.2.2')+socket.inet_aton('192.168.168.123')
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True:
data, sender = s.recvfrom(65565)
while data[-1:] == '\0': data = data[:-1] # Strip trailing \0's
# print (str(sender) + ' ' + repr(data))
notopen=1
frame_n=ord(data[0])*256+ord(data[1])
part=ord(data[2])*256+ord(data[3])
if (part==0) : # & (notopen==1)
f = open('files/'+str(frame_n)+"_"+str(part).zfill(3)+'.jpg', 'w')
fname = str(frame_n)+"_"+str(part).zfill(3)+'.jpg'
# jpeginfo -c files/2706_000.jpg
# files/2706_000.jpg 1920 x 1080 24bit JFIF N 1012 Premature end of JPEG file [WARNING]
print "\n--myboundary\nContent-Type: image/jpeg\n"
notopen=0
if notopen==0:
f.write(data[4:])
sys.stdout.write(data[4:])
if __name__ == '__main__':
main()