Why No Built in GetMyIP call in LiveCode?

John Patten johnpatten at mac.com
Fri Jun 10 18:12:53 CDT 2011


I settled on Mark's shell script process to get IP address. I managed  
to kludge together a case for Linux (Ubuntu Netbook) too. I did not  
quite understand the matchtext line with its (?s) and (.*?)'s but the  
Mac OSX case and Linux case almost worked without any changes.

The Linux shell is same as Mac's: ifconfig with either eth5 or wlan3  
for interfaces.
The shell command results are:
		wlan3     Link encap:Ethernet  HWaddr 00:25:d3:7c:f2:49
           	inet addr:10.58.0.91  Bcast:10.58.0.255  Mask:255.255.255.0
The only difference between the two is there are the characters  
"addr:" in front of the IP with no space too.  The OSX shell has  
spaces surrounding the IP.
Mark had mentioned that the (?s) represent spaces.
How does the matchText call know just to capture the IP address in the  
variable retVal?  It appears to look for "<space>inet<space>" and when  
it finds it magically captures just the IP address that follows it????  
How's it do that?  Does matchText automatically get the first item/ 
word following the matched text??? Not quite sure how that works, but  
it does :-)
--------------------snip----------------
break

		  case "Linux"
                         put shell("/sbin/ifconfig eth5") into  
tEthernetConfig
                         put shell("/sbin/ifconfig wlan3") into  
tWirelessConfig

                    set the itemdel to "."
                    --CHECK FOR ETHERNET CONNECTION
                    get matchText(tEthernetConfig,"(?s)inet (.*?)  
",retVal)
                    if it is false then
                            -- CHECK FOR WIRELESS CONNECTION
                            get matchText(tWirelessConfig,"(?s)inet  
(.*?) ",retVal)
                            if it is false then
                                    return "0.0.0.0"
                            end if
                    end if
          -- i have no clue how the matchtext works above but the  
retVal is returns "addr:10.X.X.X". Sooo...

   set the itemDel to ":"
           put item 2 of  retVal into cd fld "ipaddress"
           end switch

         return "0.0.0.0"



More information about the use-livecode mailing list