开发者

Detecting user from winsock data?

开发者 https://www.devze.com 2023-01-05 20:11 出处:网络
For example i create socket using winsock under account named Admin. Is there any possibility to detect which user created that socket? I would like to write in my program: This socket was c开发者_如何

For example i create socket using winsock under account named Admin. Is there any possibility to detect which user created that socket? I would like to write in my program: This socket was c开发者_如何学Pythonreated by "Admin". i am using c++


Sockets are not securable objects (see here) and so cannot have a security descriptor associated with them and so there's no way you can know the user account that 'created the socket'.

You could use GetExtendedTcpTable to get information about connections and then locate the PID of the process that created the socket; you could then decide to use something based on the process...

Why do you want to do this anyway?


netstat -o should give you process IDs which created the socket; from there, you can find the process owner. If everything else fails, you could spawn netstat in a new process and parse the output.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号