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.

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);