Getting the local IP address! (was Re: Scanning machines on a network)
Dar Scott
dsc at swcp.com
Fri Mar 15 00:31:01 EST 2002
On Monday, March 11, 2002, at 06:09 PM, Sarah Reichelt wrote:
> Here is a script to get your local IP address and store it in a field:
>
> local testSock
>
> on mouseUp
> put line 1 of hostnametoaddress("yahoo.com")& ":80|testSocket" \
> into testSock
> open socket to testSock with message "socketReady"
> end mouseUp
>
> on socketReady pSock
> put hostAddress(pSock) into fld "Local IP address"
> close socket testSock
> end socketReady
Here is a script that works on Windows 2000. I rejected it
earlier, because it did not work on OS X. Since other features of
UDP that work on W2K also work on Mac OS 9 (I hear), this might,
too.
This method does not actually touch another computer. (The open
for UDP does not initiate a connection dialog between computers as
open for TCP would; the local computer simply gets ready to send
packets and in this case none are sent.)
local testSock
on mouseUp
put "255.255.255.255:43222" into testSock
open datagram socket to testSock -- opens immediately on Win2K
put hostAddress(testSock) into field "Local IP Address"
close socket testSock
end mouseUp
This could be made into a function. Yay! I like functions.
(There might be another method using "shell" or "read from process"
but for some reason those don't seem to be supported on OS X; the
OS X icon is crossed out for those commands in the dictionary.)
Should anybody check out this script on Linux or Mac OS, I'd be
pleased to hear how it works.
Dar Scott
Revolution Newbie near the northern Rio Grande
More information about the use-livecode
mailing list