how do I request a new and available local port (TCP) to use with shell script?
MAybe you can use the network status command
netstat -na
and check the ports if the port you want is allready used or not. Namely you can use port and for its availability status from netstat command output inside a comparative loop
If you have nmap on your system then try that