I am writing a web proxy and when a request comes in (typically from the browser on the machine), I'd like to also get the pid and any other requesting application. Is there any way to determine this using Win32?
相关问题
- Multiple sockets for clients to connect to
- the application was unable to start correctly 0xc0
- Handle button click in another application
- 反爬能检测到JS模拟的键盘输入吗
- 有没有方法即使程序最小化也能对其发送按键
What you are asking for is only possible if the client and server are running on the same machine.
When a client is connected to the proxy, the proxy can use
getpeername()
to query the socket for the remote client IP/Port (or use the IP/Port reported byaccept()
) andgetsockname()
to get its local server IP/Port. Then the proxy can useGetTcpTable2()
(IPv4) orGetTcp6Table2()
(IPv6) to retrieve a list of active TCP connections and loop through it looking for a connection that matches the IP/Port pairs. If found, the list entry will tell you the process ID that owns that connection.For example: