title: Is there a way to monitor what process sends UDP packets (source/dest IP and port) in Windows?
body: <p>I discovered almost accidentally that my machine was sending and receiving UDP packets to a machine in Poland.  Not that I have any problem with Poland, I just don't know why my laptop has the need to communicate with a server there.  Reverse DNS shows just the ISP providing the address to some end user.  Using Wireshark, I can monitor the messages, which were indecipherable as they were probably encrypted.  All packets sent from my machine had the same source port, so clearly the application that sent them opened this UDP socket to use it.  I am searching for ways to:</p>
  
  <p>1) enumerate all current sockets open in the system, including the process that created it and, for both TCP and UDP, what ports and addresses they are current bound to.  </p>
  
  <p>2) because applications can open these sockets, use them, and close them right away,  I would love to find (or perhaps even write) a program that once started would somehow get notification each time a socket gets created, or really more importantly when bound to a source and/or destination address and port.  For UDP, I would love to also be able to monitor/keep track of the destination IP addresses and ports that socket has sent messages to.</p>
  
  <p>I don't want to monitor the traffic itself, I have Wireshark if I want to view the traffic.  I want to be able to then cross reference to discover what application is generating the packets.  I want to know if it is from a process I trust, or if it is something I need to investigate further.  </p>
  
  <p>Does anybody know of any applications (for the Windows platform) that can do this?  If not, any ideas about a .NET or Windows API that provides this capability, should I want to write it myself?</p>
  
  <p><strong>Edit</strong>:
  <em>After further research - looks like the APIs to use are GetExtendedUdpTable  and GetExtendedTcpTable, CodeProject.com has some samples wrapping these in .NET (see <a href="http://www.codeproject.com/Articles/14423/Getting-the-active-TCP-UDP-connections-using-the-G" rel="noreferrer">http://www.codeproject.com/Articles/14423/Getting-the-active-TCP-UDP-connections-using-the-G</a>). So a combination of this API and some sniffer code would be needed to monitor and keep track of what hosts at what ports using what protocol any particular application on your machine is talking to.  If I ever get some free time, I'll consider creating this, if you know of an app that does all this, please let me know.</em></p>