Is there any way to find the port firefox url listens to when we open a url.
platform - ubuntu or any other linux distro
Practically speaking, no, for a couple of reasons. 
First, multiple connections: when you open, say, http://www.example.com/, 99.9% of the time, the first page will have HREFs to other pages, often more than one. Firefox will typically open multiple additional connections to simultaneously pull down those different pages. So there isn't "a port" but multiple ports.
Second, there's simply no clean way to find out what port firefox is using. Every time firefox opens a connection, it simply creates a socket and connects. The kernel dynamically allocates an unused port for that socket. Firefox may not even aware of the port number itself (it could get that info if it wants, but I can't see why it would be doing so). The result is derivable via lsof(8), but that wouldn't give it to you in real-time. I.e. For most URLs, by the time you ran lsof and decoded the information, it would be stale (the connection would be closed).
The port could also (potentially) be gotten by ptrace(2)ing firefox (or letting strace(1) do that). But you would probably drastically affect the performance of firefox by doing so. And decoding the output would be quite complicated.
Python script to dynamically find the port to which firefox listens on opening a url?