![]() |
So its my first day at programming in C with socket connection, and I have a problem. I wrote this portscanner (cause I'm a security-type guy) in C. It works orgasmically (good) inside the network.....but if I try scanning a host over the internet, it just freezes and halt on any closed port. Anyway to fix that?
Heres the code: :
|
You need to set a logical timeout for response packets over the internet.
|
I assume what is happening here is you are hitting a computer that does not exist or you are hitting a computer which simply is dropping packets and not responding, connect will not return if this does not happen and it takes a LONG time for each connect to timeout.
Option 1) Manually turn down your time-out settings, only problem is this will give false negatives on slower machine or with bad network conditions, and hey it happens all the time. Option 2) Use non-blocking connections, you should always use this for a port scanner anyway.... because it causes the system to not block on the connect command while waiting for either an accept, deny, or timeout to occure. You will need to change your code a bit if this is the case though, after all connects you will need to monitor your sockets for incoming data about the status of those connections, likely using the select command (google this to make sure that is the most efficient way). Option 3) Actually a combination of both 1 + 2 are probably beneficial. Also remember to disable TCP nagle, you can google this as well, it is a simple flag you set at socket level and it will prevent delays in outgoing data. (Though in all honesty I can not be sure this applies with socket connections, but it does not hurt to assume that it does). |
| All times are GMT -5. The time now is 8:01 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC