Page 1 of 1

Scanning for IP addresses

Posted: Thu May 06, 2004 7:55 pm
by Killswitch
Is there a quick and easy way to check on Ip address works? I've tried using opennetworkconnection(ect,ect) but it takes forever to come back with a null result, and with 250 possibilties to run through it just takes too much time:

Code: Select all


ip$="???.???.???."
for t=1 250
new$=ip$+str(t)
dia=opennetworkconnection(new$,6000)
next t


(plus all the relevent if's - but I can't be bothered to type them, I do know that they work with a fixed Ip though.)

I've also tried using examineipaddresses() but it didnt seem to work either.


Another question:

Can you run a program that's hosted on your webspace with runprogram() and create a server there using createnetworkserver()? It would slove this entire problem if you can.

Thanks.

(Posted in the right forum this time)

Posted: Thu May 06, 2004 8:26 pm
by fweil
Killswitch,

Hopefully you did not post it at the Bugs room !

Code: Select all

ip$="???.???.???." 
For t=1 To 250
new$=ip$+Str(t) 
dia=OpenNetworkConnection(new$,6000) 
Next t 
... will return "???.???.???." ° a number. This is a normal behaviour of Purebasic, as it is exactly what you asked for !

Maybe something like :

Code: Select all

  If InitNetwork()
      NotTooMuch = $FFFFFF
      WhateverYouWant = NotTooMuch
      For t = 1 To WhateverYouWant
        Debug IPString(t)
        ConnectionID = OpenNetworkConnection(IPString(t),80)
        If ConnectionID
            Debug "Found a server at : " + IPString(t)
            CloseNetworkConnection(ConnectionID)
        EndIf
      Next t
  EndIf
  CallDebugger
End
... would work better, do yo uthink so ?

Rgrds

Re: Scanning for IP addresses

Posted: Thu May 06, 2004 11:49 pm
by Doobrey
Killswitch wrote: I've tried using opennetworkconnection(ect,ect) but it takes forever to come back with a null result, and with 250 possibilties to run through it just takes too much time:
The quickest way is to launch each OpenNetworkConnection() in it`s own thread, that way you don`t have to wait for the previous attempt to timeout before trying another IP address.
Even then it`s still not foolproof.
OpenNetworkConnection() needs an IP address and a port number to connect to, so even if the computer with the given IP address is online, unless it has that port open and waiting for a connection, then the command will still fail.
A better way is to 'Ping' the other computer, but even then it might have a firewall set up to reject ICMP packets.
Can you run a program that's hosted on your webspace with runprogram() and create a server there using createnetworkserver()? It would slove this entire problem if you can.
That`s entirely down to your hosting company. Most likely they`ll say no, as they don`t like unknown code running on their machines.
(If it`s a colocated box, then it`s yours to run whatever you want.)
Anyway, even if they allowed it, you couldn`t start it with RunProgram() unless you somehow managed to get the server mounted as a network share.

Posted: Fri May 07, 2004 4:36 pm
by Killswitch
I had though of using ping, but for my program (which im planning to distribute throughout my school friends), has a target audience who think DOS is a way to spend a lesson doing nothing.

However, I did think of using a batch file to run ping hostname$ and then save that result to a file (the upload that file to a specifed FTP which my clients can look for).

Is there an easy way to pass variables between PB and DOS, and just get the IP address from ping whatever instead of all the pining [ect] ect ect that would just confuse the matter..?

Posted: Fri May 07, 2004 4:47 pm
by freak
You could also use this:

viewtopic.php?t=3717&highlight=ping

Timo