Scanning for IP addresses

Just starting out? Need help? Post your questions and find answers here.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Scanning for IP addresses

Post 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)
~I see one problem with your reasoning: the fact is thats not a chicken~
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Re: Scanning for IP addresses

Post 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.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post 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..?
~I see one problem with your reasoning: the fact is thats not a chicken~
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You could also use this:

viewtopic.php?t=3717&highlight=ping

Timo
quidquid Latine dictum sit altum videtur
Post Reply