Regarding which port was used it should be possible to get that information from winsock library on Windows. I think the answer can be found here:
https://forums.ni.com/t5/LabVIEW/Is-it-possible-to-extract-the-local-port-associated-with-a-TCP/td-p/459672