title: How to get the client's ip on the server for remote desktop
body: <p>I am using the following function to implement a program that changes its behavior depending on the IP of the connected PC.<br />
  There is a problem with this function that if something tries to login and fails, it may get the IP of the failed one.<br />
  And now that we've encountered that possibility, the program is broken.<br />
  What edits do I need to make to make this function behave as expected?</p>
  <pre class="lang-py prettyprint-override"><code>import psutil
  
  def get_ip(port=3389):
      ip = &quot;&quot;
      for x in psutil.net_connections():
          if x.status == &quot;ESTABLISHED&quot; and x.laddr.port == port:
              ip = x.raddr.ip
              break
  </code></pre>