| | |
Winsock and looping issues unsure how to resolve
Thread Solved |
•
•
Join Date: May 2005
Posts: 41
Reputation:
Solved Threads: 0
I'm busy writing an application for work which needs to connect to a list of our servers and check some ports to ensure the correct ones we require are open and ones we don't use are closed.
I'm using winsock and checking for a connection and the results are being written out to a csv file so we can then filter various settings.
if I use a single ip i am fine the program works without a problem, the issues arise when I incorperate a loop to cycle through and only if i use them same sockets repeatedly.
ie: I'm looking at 10 ports on 50 servers
i've set my portlist up and loadup the sockets, then assign the relevant values to winsock then connect. If I connect or not I then close the socket so I can then use on next ip. But it only seems to pull through the last ip in the list, and not the others.
How can I delay the loop long enough for it to do each ip correctly, instead of skipping them
I'm using winsock and checking for a connection and the results are being written out to a csv file so we can then filter various settings.
if I use a single ip i am fine the program works without a problem, the issues arise when I incorperate a loop to cycle through and only if i use them same sockets repeatedly.
ie: I'm looking at 10 ports on 50 servers
i've set my portlist up and loadup the sockets, then assign the relevant values to winsock then connect. If I connect or not I then close the socket so I can then use on next ip. But it only seems to pull through the last ip in the list, and not the others.
How can I delay the loop long enough for it to do each ip correctly, instead of skipping them
I don't use winsock. It's functionality is limited in the realm of sockets, and to make matters worse, I find the code you need to work with it... well, leaves a lot to be desired. I prefer the use of a control that is free from http://www.catalyst.com, known as socketwrench. It makes working with sockets 100 times easier, and it gives a whole list of properties and methods that make winsock look like a joke. Anyhow, I have written a port-scanner in VB6, and you can download the source from this thread:
http://www.daniweb.com/techtalkforums/thread18197.html
Let me know if this helps! If you really MUST use winsock, maybe the concept behind how my port scanner runs will help give you the same idea to use with your winsock app.
http://www.daniweb.com/techtalkforums/thread18197.html
Let me know if this helps! If you really MUST use winsock, maybe the concept behind how my port scanner runs will help give you the same idea to use with your winsock app.
•
•
Join Date: May 2005
Posts: 41
Reputation:
Solved Threads: 0
Thanks,
looked at TTPScan and gets error loading cswsk32.ocx on loading into vb.
I still loaded at had a look, seems to be doing exactly same as I'm trying, but if I add under
the following
and place a Next before the End Sub, I get exactly the same error I get in my code
If I close the port after connecting or not then when goes to next ip in list, it doesn't display info for the first ip.
As we're going to put this on one of servers, which we use to update our customers with, I need it to go through a list, of ip's and connect to each, check 10 ports, and then create a report to be sent to the managers listing any problems found.
looked at TTPScan and gets error loading cswsk32.ocx on loading into vb.
I still loaded at had a look, seems to be doing exactly same as I'm trying, but if I add under
•
•
•
•
/* If We Are NOT Scanning Just Well Known Hosts */
•
•
•
•
For myloop = 1 To ScannedList.Count
Text1.Text = ScannedList.Item(myloop)
•
•
•
•
Run-time error '40020':
Invalid operation at current state
As we're going to put this on one of servers, which we use to update our customers with, I need it to go through a list, of ip's and connect to each, check 10 ports, and then create a report to be sent to the managers listing any problems found.
•
•
•
•
looked at TTPScan and gets error loading cswsk32.ocx on loading into vb.
I'll be willing to bet, the error that you are recieving however, is because the socket is still connected. With winsock, you have to use .state (socketwrench has a .connected property) to test if the socket is connected before trying to reconnect. So, you do a loop with a doevents in the middle, and wait for the socket's state to become closed. Another thing to take into consideration, is maybe instead of a for loop, try using a variable that keeps track of which server you are scanning, and when the list of scanned ports completes, if it's the last port to scan for that IP, on the socket's error or connect event, call a socket close (disconnect), and start on the next IP.
The problem with the for loop, is that it doesn't wait. It loops each iteration until it's done, and the only way to get it to stop is to break out of it or use a sleep. The sleep will pause your entire app though, not just the loop. So, we need to look at working with event driven looping. On Error, On Connect, On Close, etc. The socket is a control array, so it's not that difficult to check if we are on a our final port by using the passed "index". Also, I don't know if it makes any difference, but you start your for loop at 1, and i'm wondering if the first IP is at 0?
•
•
Join Date: May 2005
Posts: 41
Reputation:
Solved Threads: 0
thanks for the info I will give that a try and let you know how it works out
i had set the loop count to 1 just for routine for testing as noticed the combobox list actually pulls the scanlist.txt file in at start index of 1 and not 0.
I did also notice that unlike delphi you can't use combobox1.clear which resets a combobox and then allows you to load data starting ar point 0.
i had set the loop count to 1 just for routine for testing as noticed the combobox list actually pulls the scanlist.txt file in at start index of 1 and not 0.
I did also notice that unlike delphi you can't use combobox1.clear which resets a combobox and then allows you to load data starting ar point 0.
•
•
Join Date: May 2005
Posts: 41
Reputation:
Solved Threads: 0
Hi Comatose,
Sorry for delay in responding to this but been very busy.
But first thanks for the help
Well the news is I've managed to do what I need it to do.
I've used the socketwrench control due to the timeout parameter.
I store a list of ports to be scanned in an ini file which is loaded everytime the program is run. You can add or remove ports and this will also change the listview box settings.
It then asks for a file with the list of ip's to scan, and loads those into an array. Then goes about checking the ports required on each ip, and writes the results to a csv file, as well as displaying on the screen
regards
mrmike
Sorry for delay in responding to this but been very busy.
But first thanks for the help
Well the news is I've managed to do what I need it to do.
I've used the socketwrench control due to the timeout parameter.
I store a list of ports to be scanned in an ini file which is loaded everytime the program is run. You can add or remove ports and this will also change the listview box settings.
It then asks for a file with the list of ip's to scan, and loads those into an array. Then goes about checking the ports required on each ip, and writes the results to a csv file, as well as displaying on the screen
regards
mrmike
![]() |
Similar Threads
- USB Ports not recognizing periferals (USB Devices and other Peripherals)
- internet connection dissappears every few minutes (Networking Hardware Configuration)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: help on data type conversion
- Next Thread: blnWaitOnReturn of wshShell.Run has no effect if required application is already runn
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






That's Great!!!!! 