3 socket Q's

Sarah Reichelt sarahr at genesearch.com.au
Sun Mar 28 22:27:12 EST 2004


> 1. This returns my local IP address on all my machines not
>    connected to my router:
>
>      get hostnametoaddress(hostname())
>
>    But behind my router it returns empty.  Why?
>    And what is the reliable way to obtain the local IP address?
>
> Hi Richard,

Do you actually want the router's address (so people can connect to you 
from outside your firewall) or your own computer's address?

For getting the router's address, I log on to checkip.dyndns.org:

function routerIPaddress
   put "http://checkip.dyndns.org/" into theURL
   put URL theURL into theData
   get lineOffset("Current IP Address:", theData)
   put last word of line it of theData into ipAddr
   if ipAddr contains "<" then delete char offset("<", ipAddr) to -1 of 
ipAddr
   return ipAddr
end routerIPaddress

Make sure it never gets called in rapid succession or they will 
blacklist you!

For getting my internal address, I use the method Dar described of 
opening a socket to a web site and then using the hostAddress function:

on mouseUp
   put empty into fld "IP address"
   put line 1 of hostnametoaddress("genesearch.com.au")& 
":80|testSocket" \
       into testSock
   open socket to testSock with message "socketReady"
end mouseUp

on socketReady pSock
   put hostAddress(pSock) into fld "IP address"
   close socket pSock
end socketReady

Hope this helps,
Sarah



More information about the use-livecode mailing list