Why No Built in GetMyIP call in LiveCode?

John Patten johnpatten at mac.com
Fri Jun 10 19:12:53 EDT 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:  Bcast:  Mask:
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 :-)

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

                    set the itemdel to "."
                    get matchText(tEthernetConfig,"(?s)inet (.*?)  
                    if it is false then
                            -- CHECK FOR WIRELESS CONNECTION
                            get matchText(tWirelessConfig,"(?s)inet  
(.*?) ",retVal)
                            if it is false then
                                    return ""
                            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 ""

More information about the Use-livecode mailing list