-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeliver.py
32 lines (26 loc) · 1.02 KB
/
Deliver.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
# some imports
import socket, sys
from struct import *
proto=89
AllSPFRouters= '224.0.0.5'
def deliver(packet, addr_int, destination, multicast):
if multicast:
multicat_group=(AllSPFRouters, proto)
# create a raw socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, proto)
for x in addr_int:
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(x))
s.settimeout(0.2)
except socket.error as msg:
sys.exit()
return 'Socket not be created. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
# Send the packet finally - the port specified has no effect
s.sendto(packet, multicat_group)
else:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, proto)
except socket.error as msg:
return 'Socket not be created. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
# send packet
s.sendto(packet, (destination, proto))