cleaner local ip address lookup (#244)
This commit is contained in:
		
							parent
							
								
									a75f98720e
								
							
						
					
					
						commit
						b8fdf337c9
					
				
					 1 changed files with 1 additions and 3 deletions
				
			
		| 
						 | 
					@ -63,9 +63,7 @@ def gendevice(devtype, host, mac):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def discover(timeout=None, local_ip_address=None):
 | 
					def discover(timeout=None, local_ip_address=None):
 | 
				
			||||||
    if local_ip_address is None:
 | 
					    if local_ip_address is None:
 | 
				
			||||||
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 | 
					        local_ip_address = socket.gethostbyname(socket.gethostname())
 | 
				
			||||||
        s.connect(('8.8.8.8', 53))  # connecting to a UDP address doesn't send packets
 | 
					 | 
				
			||||||
        local_ip_address = s.getsockname()[0]
 | 
					 | 
				
			||||||
    address = local_ip_address.split('.')
 | 
					    address = local_ip_address.split('.')
 | 
				
			||||||
    cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 | 
					    cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 | 
				
			||||||
    cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 | 
					    cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue