forked from p34709852/monkey
find tunnel now searches on all host's interfaces
This commit is contained in:
parent
3990806d8c
commit
3dacde2f28
|
@ -20,11 +20,11 @@ DEFAULT_TIMEOUT = 10
|
|||
QUIT_TIMEOUT = 60 * 10 # 10 minutes
|
||||
|
||||
|
||||
def _set_multicast_socket(timeout=DEFAULT_TIMEOUT):
|
||||
def _set_multicast_socket(timeout=DEFAULT_TIMEOUT, adapter=''):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
|
||||
sock.settimeout(timeout)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(('', MCAST_PORT))
|
||||
sock.bind((adapter, MCAST_PORT))
|
||||
sock.setsockopt(socket.IPPROTO_IP,
|
||||
socket.IP_ADD_MEMBERSHIP,
|
||||
struct.pack("4sl", socket.inet_aton(MCAST_GROUP), socket.INADDR_ANY))
|
||||
|
@ -32,12 +32,13 @@ def _set_multicast_socket(timeout=DEFAULT_TIMEOUT):
|
|||
|
||||
|
||||
def find_tunnel(default=None, attempts=3, timeout=DEFAULT_TIMEOUT):
|
||||
sock = _set_multicast_socket(timeout)
|
||||
|
||||
l_ips = local_ips()
|
||||
|
||||
for adapter in l_ips:
|
||||
for attempt in range(0, attempts):
|
||||
try:
|
||||
LOG.info("Trying to find using adapter %s", adapter)
|
||||
sock = _set_multicast_socket(timeout, adapter)
|
||||
sock.sendto("?", (MCAST_GROUP, MCAST_PORT))
|
||||
tunnels = []
|
||||
if default:
|
||||
|
|
Loading…
Reference in New Issue