forked from Tanganelli/CoAPthon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coapforwardproxy.py
48 lines (36 loc) · 1.13 KB
/
coapforwardproxy.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
43
44
45
46
47
48
#!/usr/bin/env python
import getopt
import sys
from coapthon.forward_proxy.coap import CoAP
__author__ = 'Giacomo Tanganelli'
class CoAPForwardProxy(CoAP):
def __init__(self, host, port, multicast=False, cache=False):
CoAP.__init__(self, (host, port), multicast=multicast, cache=cache)
print "CoAP Proxy start on " + host + ":" + str(port)
def usage(): # pragma: no cover
print "coapforwardproxy.py -i <ip address> -p <port>"
def main(argv): # pragma: no cover
ip = "0.0.0.0"
port = 5684
try:
opts, args = getopt.getopt(argv, "hi:p:", ["ip=", "port="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
usage()
sys.exit()
elif opt in ("-i", "--ip"):
ip = arg
elif opt in ("-p", "--port"):
port = int(arg)
server = CoAPForwardProxy(ip, port)
try:
server.listen(10)
except KeyboardInterrupt:
print "Server Shutdown"
server.close()
print "Exiting..."
if __name__ == "__main__": # pragma: no cover
main(sys.argv[1:])