Sorry - trying to understand what you are asking - i think you are saying you want to run multiple instances of NR on a single box on different ports ?
You are then asking can you query from within a flow to see which port that instance is running on ?
One way would be to add a global variable in settings.js
However, you need to do it in a specific way that requires some changes to how settings.js is structured.
Normally, settings.js is structured like this:
module.exports = {
... all the settings
}
What you need to do is move the settings to their own variable and then export that. It lets you reference the content of the variable before it is exported which lets you get hold of things like the port which is dynamically allocated on startup.
Of course, you will need to test whether setting the port using the -p argument sets the port early enough to be picked up.
Of course, using the port setting I've used above would mean that you could set the port using an environment variable and you could also pass the env variable to global.