title: Find remote IP address and port number for a TCP socket using linux command line
body: <p>I have the below entry in <code>strace</code> for one of my programs</p>
  <pre><code>[pid 13759] 08:17:14 sendto(657, &quot;*** Needed to remove the message for confidentiality ***&quot;..., 729, 0, NULL, 0) = 729 &lt;0.000097&gt;
  [pid 13759] 08:17:14 recvfrom(657, &quot;*** Needed to remove the message for confidentiality ***&quot;, 2048, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;*removed*.*removed*.129.16&quot;)}, [28-&gt;16]) = 114 &lt;0.000031&gt;
  </code></pre>
  <p>The above <code>sendto</code> and <code>recvfrom</code> systems calls are operating on socket 657. I need to figure out what is the remote IP address and port corresponding to the socket number 657. Can you please suggest the linux command to get the aforementioned information?</p>
  <p>One way of doing it is to start the <code>strace</code> before the TCP connection is established. The remote IP address and port number are printed in the <code>connect</code> system call when the TCP connection is established. I cannot use this approach because in my case (on the prod system) the TCP connection was established much earlier and I cannot really do a restart of the application.</p>
  <p>I am using Ubuntu <code>VERSION=&quot;18.04.6 LTS (Bionic Beaver)&quot;</code>.</p>
  <p>Help will be much appreciated. Thank you.</p>