How do you get the active animation controller?

After double clicking on an animation controller asset the animator window will open and allow you to inspect the controller. Is there a way to find out what the controller that is active in that window is?

I noticed you can get the state that is selected in that window through Selection.activeObject but I can’t find a path back to the controller from there.

Reflection is the answer to the universe.

// https://gist.github.com/forestrf/29c391c7cae0202ea18392b03bb70ac1
public AnimatorController GetCurrentActiveController()
{
    string typeName = "UnityEditor.Graphs.AnimatorControllerTool, UnityEditor.Graphs";
    Type t = Type.GetType(typeName);
    EditorWindow animator = GetWindow(t);
    BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
    FieldInfo objectField = t.GetField("m_AnimatorController", bindingAttr);
    return (AnimatorController)objectField.GetValue(animator);
}