Click to See Complete Forum and Search --> : which process listens to which socket?


mtdashti
May 22nd, 2002, 06:06 AM
hi,

in fact i've asked this question in vc++ room, but there is no answer yet! i want to write a program that determines which process on my pc listens to which socket, but i have no idea how to write it. can u help me??

if u are familiar with inzider.exe (ntsecurity.nu) or fport.exe (foundstone.com) these are what i wana write.
thanx for attention.

avantos
May 23rd, 2002, 05:47 AM
This is not a coded way of doing it, infact it's kind of a cop-out. Anyways, if you have access to the computer and it is running windows... A very, very simple way to find out, install and run zonealarm. It'll tell you everything trying to access the internet and which ports they are listening to.

mtdashti
May 25th, 2002, 01:07 AM
thanx for attention,


in fact any firewall or the tiny programs that I named in my question would do it but i want to know how do they know these information about listening ports and processes???

avantos
May 25th, 2002, 01:29 AM
Well, I only have a limited knowledge of how sockets and ports work. So here's pretty much everything i know..heh

You cannot bind two sockets to the same port. So you can make a for-loop and try to bind a socket to every port. If it fails, you know the port is in use by something else. Next, (there has to be a better way, but i don't know it), you could try to connect to the ports that you have already determined are in use. If the connect fails, then you know it is not a listening socket. If it works, you know it is.

This is probably the most crude way of doing it, but it will at least tell you which sockets are in use and whether or not they are a listening socket.

Oh, actually, a second way...once you have tried to bind an have determined which sockets are in use.

getsockopt() will tell you whether or not the socket is a listening socket.


Sorry I couldn't be of more help.

-Avantos

mtdashti
May 25th, 2002, 02:23 AM
ok, thanx for attention.
if i ever solved the problem, i'll tell u!! ;)