#include 'CabDefs.ch' //////////// // GetIp.prg //////////// //////////// // FUNCTION GetIP_(cError) // Obtém o IP do computador onde é executada, onde: // [<@cError>] -> variável que conterá uma descrição de erro de acesso, ou "" // Retorna: IP do computador // '' se não foi possível detetar o IP // // 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 cIP := ApiLoadFromURL_('http://IfConfig.me/ip') // From Phil Ide cError := ApiLoadFromUrlStatus_() // From Phil Ide. if Empty(cIP) .or.; Len(cIP) > 20 cIP := ApiLoadFromURL_('http://IcanHazIP.com/') cError := ApiLoadFromUrlStatus_() if Empty(cIP) .or.; Len(cIP) > 20 cIP := ApiLoadFromURL_('http://CheckIP.DynDNS.org/') cError := ApiLoadFromUrlStatus_() if Empty(cIP) cIP := '' else cIP := Lower(cIP) if 'current ip address: ' $ cIP cIP := StrTran(cIP, 'current ip checkcurrent ip address: ') cIP := StrTran(cIP, '') elseif Len(cIP) > 20 cIP := '' endif endif endif endif cIP := AllTrim(cIP) RETURN StrTran(StrTran(cIP, CR, ''), LF, '') //////////// // FUNCTION GetIPReverse_(cIP, cMens) // Returns the DNS (Domain Name System) from an IP, where: // -> IP for wich is desired the DNS // [<@cMens>] -> error message or '' // ///// LOCAL cCmdComm, cPingComm, cParameters, cIpAtRight, cWork, cPing, nAt, cDNS, nInd, cLine do while .t. cCmdComm := GetEnv('ComsPec') cCmdComm := Left(cCmdComm, (RAt('\', cCmdComm))) if Empty(cCmdComm) cDNS := '' exit endif do while .t. // // GetTempPath_() returns the temporary folder of the computer // ApiGetTimeGranular_() returns miliseconds for to create a working file name cWork := (GetTempPath_() + 'Wk' + Right(StrZero(ApiGetTimeGranular_(cabTIME_MILISECONDS), 11), 6) + '.txt') FErase(cWork) if !Fexists(cWork) exit endif Sleep(30) enddo cPingComm := (cCmdComm + 'ping.exe') cCmdComm += 'cmd.exe' cParameters := ('/c ping.exe -a ' + cIP + ' -n 1 > ' + cWork) cPingComm += cParameters cIpAtRight := (' [' + cIp +']') // // ApiRunShell_() is almost the function RunShell() of Xbase++. Ir returns // execution error cMens := ApiRunShell_(cabRUN_OPEN, cCmdComm, cPingComm, CurDir(), SW_HIDE) if !Empty(cMens) cDNS := '' exit endif // // Waiting for the file resulting the "ping" to be written nInd := 1 do While .t. cPing := MemoRead(cWork) if !Empty(cPing) exit endif Sleep(30) nInd += 1 if nInd == 50 exit endif enddo if nInd == 50 cDNS := '' exit endif // // Processing the file for nInd := 1 to 25 cLine := MemoLine(cPing, 80, nInd) if !Empty(cLine) exit endif next if Empty(cLine) cDNS := '' exit endif nAt := RAt(cIpAtRight, cLine) if nAt == 0 cDNS := '' exit endif cLine := Left(cLine, (nAt - 1)) nAt := RAt(Space(01), cLine) if nAt == 0 cDNS := '' else cDNS := SubStr(cLine, (nAt + 1)) endif exit enddo FErase(cWork) RETURN cDNS