Reputation: 7636
I'm trying to get the ipaddress that a process is connected to in c#. Is there an easy way to do this?
Upvotes: 0
Views: 2501
Reputation: 4828
There are two ways to achieve this:
InternalGetTcpTableWithOwnerModule
/ InternalGetUdpTableWithOwnerModule
/ InternalGetTcp6TableWithOwnerModule
/ InternalGetUdp6TableWithOwnerModule
APIs exported from iphlpapi.dll.netstat -b
and parse the output.Either way you will need administrator privileges and both ways are bound to break with different Windows versions. It is most certainly possible to create a Windows driver with documented APIs, but that would be a lot of work.
Update:
There is actually a documented API too - GetExtendedTcpTable and GetExtendedUdpTable. Also there's an article which presents an example how to call it from C#.
Upvotes: 3