As goldilocks' comment says, this is extremely heterogeneous. A printer isn't a "port" in the sense you mean, there is a whole software infrastructure handling the queues of print jobs (CUPS here, there are other alternatives). The printer might be off/disconnected, but jobs waiting. What does a USB port "in use" mean? An unmounted pendrive is plugged in? What if a USB hub is connected, and nothing is connected to it? What is a monitor "in use"? A connected user, a screensaver running, a GDM greeter?
For some of the devices it might not be possible to determine if something is connected without some activity.
And that leaves out Bluetooth and other wireless stuff.
It makes much more sense to ask e.g. if sound output is available, without regard if it is on-board, via USB, by Bluetooth, or maybe even over WiFi to some media center. I.e., ask if some functionality is available, not ask for (perhaps ephemeral) devices.