IP Address Scanning

I am learning Xojo and am trying to build an IP address scanner, so I can see which servers are “online” at a given time.

I tried the TCPSocket example (from the Xojo documentation), as that allows me to connect to one server address easily without issues. However, the moment that try to enclose the code within a loop, so that it checks out a list of potential server addresses, it freezes without any explanation. Hmm…

Thoughts? Ideas?

[code]dim soc As New TCPSocket
dim counter as Integer

for counter = 1 to 255
soc.Address = “10.0.1.” + str(counter)
soc.Port = 80

// Make connection attempt.

// While attempting to connect…
While Not soc.IsConnected
If soc.LastErrorCode <> 0 Then
End If

// Finally, connected!
If soc.IsConnected Then
End If

// Now, disconnect.

may be because system default timeout for no connection can be as long as 300s so 5 mins. and you think it’s freezed, but it is only waiting timeout ?
you can switch to xojo while your app is running, hit “pause” button, and see where it is “freezing” .
let it wait some minutes to pause before saying it’s freezed.

I suspect you are running into a problem with your tight while loop. Socket events fire on the main thread, but your main thread is so busy looping to check for isConnected that the socket events never actually get to fire, so isConnected never gets set, and you sit there hammering soc.Poll in the while loop.

Have you tried putting any breakpoints in your code in the debugger to see how far through your loop it is getting?

Ah, I didn’t realize that the pause button would allow you to see where the traffic jam was occurring!

Yes, I think you’re right – it looks like its getting jammed up at the soc.isConnected area. The while loop is trying to process the connections way too quickly. Hmm.

Any ideas or suggestions on how one should do network discovery for local servers running? :slight_smile:

Your question is pretty broad. Let’s try to narrow it down some:
Are you also writing the servers you are looking for? Or are you looking for existing stuff? (i.e, scan the network for all apache servers, or postfix server I can get to, etc)

youre not finding out if they’re ‘online’. port 80 is specifically looking for a web server

look here Pinging thread

@Kimball Larsen Very true. :slight_smile: What I am trying to figure out is how to identify what network resources are currently available within the local network, such as through If there is a web server (port 80), I would like my app to be able to find it. If there’s a mysql server running on the local network, I would like the app to discover that too. Most of the servers I will be searching for are not a Xojo-produced product, unfortunately.

Do you necessarily need to roll your own? What you describe is exactly what nmap does - it’s a command-line utility for scanning networks to discover hosts, and scanning hosts to discover open ports.

If your app specifically needs to do the same, perhaps you could save some work by wrapping nmap?

More information at the nmap website here.