#include 'CabDefs.ch' //////////// // GetIp.prg //////////// STATIC cPathSystem32 //////////// // FUNCTION GetComputerIP_(cError) // Returns: the computer's IP ou "" // // You can get the external IP address of your computer only from the outside // world. There is no way to determine if it is a static or dynamic IP address, // though. // There are several services that will tell you what your IP address but they don't // always work and change over time. // If they fail you can to make a Google search like "what is my IP" // The services may return a html where the IP is inside and you need to parse it for to get the IP. ///// LOCAL cIP, nAt do while .t. cIP := ApiLoadFromURL_('IfConfig.me/ip') cError := ApiLoadFromUrlStatus_() if !Empty(cIP) cIp := Left(cIp, (Len(cIp) - 1)) exit endif cIP := ApiLoadFromURL_('checkip.dyndns.org') cError := ApiLoadFromUrlStatus_() if !Empty(cIP) cIP := Lower(cIP) nAt := At('current ip address: ', cIP) if nAt > 0 cIP := SubStr(cIP, (nAt + 21), 20) nAt := At('<\', cIP) if nAt > 0 cIP := Left(cIP, (At('<\', cIp) - 1)) exit endif endif endif cIp := ApiLoadFromUrl_('ipinfo.info') cError := ApiLoadFromUrlStatus_() if !Empty(cIp) nAt := At('whois.ch?ip=', cIp) if nAt > 0 cIp := SubStr(cIp, (nAt + 12)) cIp := Left(cIp, (At('"', cIp) - 1)) else cIp := '' endif endif exit enddo if Empty(cIP) cIP := '' else cIP := AllTrim(cIP) endif RETURN StrTran(StrTran(cIP, CR, ''), LF, '') //////////// // FUNCTION GetIp_(cDNS, cError) // Gets the DNS's IPução do comando que obtém o cDNS // Returns: -> "" if the IP was not find // -> the IP IPV4 found ///// LOCAL cIP, nAt if cPathSystem32 == NIL cPathSystem32 := GetEnv('ComsPec') cPathSystem32 := Left(cPathSystem32, RAt('\', cPathSystem32)) endif cIP := '' if !ApicreateProcess_((cPathSystem32 + 'ping.exe'),; ('-a -4 ' + cDNS),; NIL,; .t.,; .t.,; @cIP,; @cError) cIP := '' else nAt := At('[', cIP) if nAt == 0 cIP := '' else cIP := SubStr(cIP, (nAt + 1)) nAt := RAt(']', cIP) cIP := Left(cIP, (nAt - 1)) endif endif RETURN cIP //////////// // FUNCTION GetDNS_(cIP, cError) // Returns the IP's DNS // ///// LOCAL cDNS, nAt if cPathSystem32 == NIL cPathSystem32 := GetEnv('ComsPec') cPathSystem32 := Left(cPathSystem32, RAt('\', cPathSystem32)) endif cDNS := '' if !ApicreateProcess_((cPathSystem32 + 'ping.exe'),; ('-a ' + cIP),; NIL,; .t.,; .t.,; @cDNS,; @cError) cDNS := '' else nAt := At('[', cDNS) if nAt == 0 cDNS := '' else cDNS := RTrim(Left(cDNS, (nAt - 2))) nAt := RAt(' ', cDNS) cIP := SubStr(cDNS, (nAt + 1)) endif endif RETURN cIP