title: Find ports a program uses with python
body: <p>I want to find the ports used by 'plugin-container.exe' so I can monitor what IP addresses interact with that program, The problem is there are two 'plugin-container.exe's.
  I use Firefox Developer Edition.</p>
  <p>I already have the monitoring part down but I need to automate getting the ports some how. From what I've seen, getting them means knowing what PID the process is using, two processes = 2 PIDs. ;_;</p>
  <p>I could add BOTH of them but there is a ton of traffic going though my browser and it kills my program when I put all 4 ports in manually.</p>
  <p>Right now I'm using this to get the list, re.findall to filter the 'plugin-container.exe' in the list, I then use psutil to find what ports.</p>
  <p>I feel like there is an easier way to do all of this.</p>
  <blockquote>
  <p>import os, sys, win32api, re, psutil</p>
  <p>tasklistrl = os.popen(&quot;tasklist&quot;).readlines()</p>
  <p>tasklistr = os.popen(&quot;tasklist&quot;).read()</p>
  </blockquote>