question about port scanning
-
Hi everybody! I want to scan the ports on my computer, and I'm looking for the right class to do that. any clues please? thanks!
-
Hi everybody! I want to scan the ports on my computer, and I'm looking for the right class to do that. any clues please? thanks!
Hi! I'm not sure about this but you could try to do it like this:
System.Net.Sockets.TcpClient myclient = new System.Net.Sockets.TcpClient(); for (int i = 0; i < 65535; i++) { try { myclient.Connect("localhost", i); // Client was able to connect, hence the specified port 'i' is open... } catch { // An Exception was thrown, hence there was a problem while connecting.. port 'i' closed? } }
This method is obviously not the best because it uses a try..catch statement and it will also throw an exception if a particular port is blocked by another application. To get around this issue you will have to extend the exceptionhandling massively. That's how i would do it but as already mentioned i'm pretty unexperienced... Good luck, mik -
Hi! I'm not sure about this but you could try to do it like this:
System.Net.Sockets.TcpClient myclient = new System.Net.Sockets.TcpClient(); for (int i = 0; i < 65535; i++) { try { myclient.Connect("localhost", i); // Client was able to connect, hence the specified port 'i' is open... } catch { // An Exception was thrown, hence there was a problem while connecting.. port 'i' closed? } }
This method is obviously not the best because it uses a try..catch statement and it will also throw an exception if a particular port is blocked by another application. To get around this issue you will have to extend the exceptionhandling massively. That's how i would do it but as already mentioned i'm pretty unexperienced... Good luck, mikHi I thought about this method, but its really not an efficient one. thanks alot anyway! :-)