def get_local_ip(target=None):
 connect_target = ('4.4.4.2' if (target is None) else target)
 try:
  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  sock.connect((connect_target, 80))
  local_address = sock.getsockname()[0]
 except Exception:
  return None
 else:
  return local_address

def get_local_ip ( target = None ) : connect_target = ( '4.4.4.2' if ( target is None ) else target ) try : sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) sock . connect ( ( connect_target , 80 ) ) local_address = sock . getsockname ( ) [ 0 ] except Exception : return None else : return local_address
returns local ip address or none .