How to get all plugins and their version numbers from the local files?

The bad news WP doesn’t track this information persistently. It only keeps the technical representation of active plugins to load them. The rest is only looked up in specific contexts (such as plugin management admin panel), because it’s relatively heavy on resources.

The good news is that you can certainly rebuild this functionality in arbitrary program. The canonical version of WP plugin is contained in its File Header in a form of PHP comment. Unfortunately it’s not too machine-friendly format.

You can have your script scan for headers, keeping in mind several quirks:

  1. Version isn’t mandatory and might be missing altogether.
  2. Plugins folder might or might not be in default location (it’s customizable).
  3. Plugins might or might not be in a subfolder (they can be directly in plugins folder).
  4. There might be multiple plugins in a single subfolder.