I had to work out the LAN IP for the machine my app is running on because the IP is needed to enter into an iPhone app so it can sync to the desktop. This is just an temporary measure while we implement zeroconf. Here’s a little modification of Ken Ray’s great GetMACAddress function to return the LAN IP.
function getLANIP
-- value to return
local retVal,tCard,ifConfigs,winExists,sys32Exists,temp
set the itemDel to "."
switch (the platform)
case "MacOS"
if item 1 of the systemVersion <10 then
return ""
else
-- OS X
repeat with X=1 to 10
put "en"&X into tCard
put shell("ifconfig "&tCard) into ifConfigs
if char 1 to 9 of ifConfigs = "ifconfigs:" then
exit repeat
else if char 1 to 4 of ifConfigs = "zsh:" then
return ""
else
get matchText(ifconfigs,"(?s)inet (.*?) ",retVal) -- These are spaces on either side of (.*?)
if it is false then
return ""
else
exit repeat
end if
end if
end repeat
end if
break
case "Win32"
-- All Windows
put (there is a file (specialFolderPath("system") & "/IPCONFIG.EXE")) into winExists
put (there is a file (specialFolderPath("system") & "/SYSTEM32/IPCONFIG.EXE")) into sys32Exists
if winExists or sys32Exists then
set the hideConsoleWindows to true
put shell("ipconfig /all") into temp
if word 2 of systemVersion() < 6 then
get matchText(temp,"IP Address[\. ]*: ([A-Z0-9-.]*)",retVal)
else
get matchText(temp,"IPv4 Address[\. ]*: ([A-Z0-9-.]*)",retVal)
end if
else
return ""
end if
break
end switch
return retVal
end getLANIP
