Why No Built in GetMyIP call in LiveCode?

Mark Talluto userev at canelasoftware.com
Fri Jun 10 13:46:39 EDT 2011


Hi John,

Hope this helps.

function getMyIp
      switch (the platform)
            case "MacOS"
                  put shell("/sbin/ifconfig en0") into tEthernetConfig
                  put shell("/sbin/ifconfig en1") into tWirelessConfig
                   
                  if char 1 to 4 of tIpConfig = "zsh:" then
                        return "0.0.0.0"
                  else
                        set the itemdel to "."
                        --CHECK FOR ETHERNET CONNECTION
                        get matchText(tEthernetConfig,"(?s)inet (.*?) ",retVal)  -- These are spaces on either side of (.*?)
                        if it is false then
                              --CHECK FOR WIRELESS CONNECTION
                              get matchText(tWirelessConfig,"(?s)inet (.*?) ",retVal)  -- These are spaces on either side of (.*?)
                              if it is false then
                                    return "0.0.0.0"
                              end if
                        end if
                  end if
                  return retVal
                  break
                   
            case "Win32"
                  put (there is not a file (specialFolderPath("system") & "/IPCONFIG.EXE")) into tWindowsError
                  put (there is not a file (specialFolderPath("system") & "/SYSTEM32/IPCONFIG.EXE")) into tSys32Error
                  if tWindowsError and tSys32Error then
                        return "0.0.0.0"
                  else
                        set the hideConsoleWindows to true
                        put shell("ipconfig/all") into tIpConfigAll
                         
                        put tIpConfigAll into temp
                        --ETHERNET XP & VISTA
                        put offset("Ethernet adapter Local Area Connection:",temp) into tOffsetResult
                        delete char 1 to (tOffsetResult-1) in temp
                        get matchText(temp,"IP Address[\. ]*: ([A-Z0-9\.]*)",retVal)
                         
                        --WIRELESS XP & VISTA
                        if retVal is empty then
                              put tIpConfigAll into temp
                              put offset("Ethernet adapter Wireless Network Connection:",temp) into tOffsetResult
                              delete char 1 to (tOffsetResult-1) in temp
                              get matchText(temp,"IP Address[\. ]*: ([A-Z0-9\.]*)",retVal)
                        end if
                         
                        if retVal is empty then --ETHERNET WIN 7
                              put tIpConfigAll into temp
                              get matchText(temp,"IPv4 Address[\. ]*: ([A-Z0-9\.]*)",retVal)
                        end if
                        if it is false then --NO NETWORK CONNECTION FOUND
                              return "0.0.0.0"
                        else
                              return retVal
                        end if
                  end if
                  break
      end switch
       
      return "0.0.0.0"
end getMyIp




Best regards,

Mark Talluto
http://www.canelasoftware.com



On Jun 10, 2011, at 10:05 AM, John Patten wrote:

> Hi All...
> 
> I've been looking at all the solutions in the archive for getting the IP address of the machine running a stack. Some shell scripts, some php calls, etc. etc.
> 
> I have a situation where we are behind a firewall using NAT. So all our computers are running a 10.x.x.x.x address. I'm trying to implement some socket communication between stacks and IP address information is essential for this to work. I would like the communication process set up to be as transparent as possible, allowing users to connect by name and maybe holding IP address is a custom property for example.
> 
> The Dictionary provides some examples for hostAdress function and I tried (wishful thinking, script trickery) something like this:
> 
> on mouseUp
>   open socket to "127.0.0.1:5005" with message "socketOpen"
>   put the result
> end mouseUp
> 
> on socketOpen theSock
>   put the hostAddress of "127.0.0.1:5005"
> end socketOpen
> 
> ...but it just gave me 127.0.0.1 and not the 10.x.x.x. address...
> 
> 
> Shell script works nice, but it gives quite a few IP in its result. Plus the actual machine IP is located on different lines in the result, such as in a desktop machine, as opposed to a laptop on wireless.
> 
> It just seems like it would be nice to have a built in function for reporting local machine's IP...
> 
> Such as, "put localIP of current stack into tIP"  or "get LocalIP of current stack."
> 
> Is this available in the dictionary and I'm just missing it?
> 
> Thank you!
> 
> John Patten
> SUSD
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list