Added static method addrinfo()
This commit is contained in:
parent
30681a7018
commit
78697b9663
25
websocket.py
25
websocket.py
|
@ -140,6 +140,17 @@ Sec-WebSocket-Accept: %s\r
|
|||
#
|
||||
# WebSocketServer static methods
|
||||
#
|
||||
|
||||
@staticmethod
|
||||
def addrinfo(host, port=None):
|
||||
""" Resolve a host (and optional port) to an IPv4 or IPv6 address.
|
||||
Returns: family, socktype, proto, canonname, sockaddr
|
||||
"""
|
||||
addrs = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)
|
||||
if not addrs:
|
||||
raise Exception("Could resolve host '%s'" % self.target_host)
|
||||
return addrs[0]
|
||||
|
||||
@staticmethod
|
||||
def daemonize(keepfd=None, chdir='/'):
|
||||
os.umask(0)
|
||||
|
@ -687,14 +698,12 @@ Sec-WebSocket-Accept: %s\r
|
|||
is a WebSockets client then call new_client() method (which must
|
||||
be overridden) for each new client connection.
|
||||
"""
|
||||
for res in socket.getaddrinfo(self.listen_host, self.listen_port, 0, socket.SOCK_STREAM, 6):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
lsock = socket.socket(af, socktype)
|
||||
lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
lsock.bind((self.listen_host, self.listen_port))
|
||||
lsock.listen(100)
|
||||
break
|
||||
|
||||
addr = WebSocketServer.addrinfo(self.listen_host, self.listen_port)
|
||||
lsock = socket.socket(addr[0], addr[1])
|
||||
lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
lsock.bind((self.listen_host, self.listen_port))
|
||||
lsock.listen(100)
|
||||
|
||||
if self.daemon:
|
||||
self.daemonize(keepfd=lsock.fileno(), chdir=self.web)
|
||||
|
||||
|
|
10
websockify
10
websockify
|
@ -150,12 +150,10 @@ Traffic Legend:
|
|||
# Connect to the target
|
||||
self.msg("connecting to: %s:%s" % (
|
||||
self.target_host, self.target_port))
|
||||
for res in socket.getaddrinfo(self.target_host, self.target_port, 0, socket.SOCK_STREAM, 6):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
tsock = socket.socket(af, socktype)
|
||||
tsock.connect((self.target_host, self.target_port))
|
||||
break
|
||||
|
||||
addr = WebSocketServer.addrinfo(self.target_host, self.target_port)
|
||||
tsock = socket.socket(addr[0], addr[1])
|
||||
tsock.connect((self.target_host, self.target_port))
|
||||
|
||||
if self.verbose and not self.daemon:
|
||||
print(self.traffic_legend)
|
||||
|
||||
|
|
Loading…
Reference in New Issue