Here we go. :D
(Bugger, don't know how to do the forum code example format thingy.)
8<----------------------------------------------------------------------------------------
;========================================
;BROADCAST IP DETERMINIFICATIONALIZOMATIC
;========================================
hadapters=CountHostIPs("")
iptest=HostIP(1) ;find broadcast IP of this adapter.
stream=CreateUDPStream(8123)
UDPTimeouts 5
Repeat
iptest=iptest+1
WriteString stream,"HELLO SAILOR"
SendUDPMsg stream,iptest,8123
recv=RecvUDPMsg(stream)
nmsg$=ReadString$(stream)
Until nmsg$="HELLO SAILOR" Or (255 And iptest)=0
CloseUDPStream stream
If nmsg$="HELLO SAILOR" Then Notify "Broadcast IP: "+DottedIP$(iptest)
If recv=0 Then Notify "Failed to determine broadcast IP. How did that happen I wonder?"
8<----------------------------------------------------------------------------------------
Crude, but effective! It seems to work. Just start off with the adapter's IP, as the broadcast IP has to be larger. Increment the IP by one, send something out, then listen to see if you get it back. If you do, you can assume you've found the broadcast IP. It means blasting a few packets out initially, but once the broadcast IP has been determined, it won't need to.
It'll probably work without that UDP timeout, but the worst case is a 1.2 second scan time, perfectly acceptable for a one-off scan time. The (255 AND IPTEST) makes sure to stop the loop in the event that the final IP digit rolls back to zero (went past 255), just as a failsafe in case something somewhere went awry.
Wahey! No nasty DLL this or DECLS that to hurt my brain! I'll put this aside for v2.1 of the game for it's browser, but no more new stuff for v2.0, or I'll NEVER get it finished...
(Bugger, don't know how to do the forum code example format thingy.)
8<----------------------------------------------------------------------------------------
;========================================
;BROADCAST IP DETERMINIFICATIONALIZOMATIC
;========================================
hadapters=CountHostIPs("")
iptest=HostIP(1) ;find broadcast IP of this adapter.
stream=CreateUDPStream(8123)
UDPTimeouts 5
Repeat
iptest=iptest+1
WriteString stream,"HELLO SAILOR"
SendUDPMsg stream,iptest,8123
recv=RecvUDPMsg(stream)
nmsg$=ReadString$(stream)
Until nmsg$="HELLO SAILOR" Or (255 And iptest)=0
CloseUDPStream stream
If nmsg$="HELLO SAILOR" Then Notify "Broadcast IP: "+DottedIP$(iptest)
If recv=0 Then Notify "Failed to determine broadcast IP. How did that happen I wonder?"
8<----------------------------------------------------------------------------------------
Crude, but effective! It seems to work. Just start off with the adapter's IP, as the broadcast IP has to be larger. Increment the IP by one, send something out, then listen to see if you get it back. If you do, you can assume you've found the broadcast IP. It means blasting a few packets out initially, but once the broadcast IP has been determined, it won't need to.
It'll probably work without that UDP timeout, but the worst case is a 1.2 second scan time, perfectly acceptable for a one-off scan time. The (255 AND IPTEST) makes sure to stop the loop in the event that the final IP digit rolls back to zero (went past 255), just as a failsafe in case something somewhere went awry.
Wahey! No nasty DLL this or DECLS that to hurt my brain! I'll put this aside for v2.1 of the game for it's browser, but no more new stuff for v2.0, or I'll NEVER get it finished...