*/--- Sintaxis: IPAddress()
*/--- Valor devuelto: lcResult
*/--- lcResult viene expresado como una cadena con el formato: 192.100.100.100, 192.100.100.101, ...
FUNCTION IPAddress
Local lnCnt, lpWSAData, lpWSHostEnt, lpHostName, lcResult, lpHostIp_Addr, ;
lpHostEnt_Addr, lnHostEnt_Lenght, lnHostEnt_AddrList
*/--- Windows Sockets
#DEFINE WS_VERSION_REQD 257
#DEFINE WS_VERSION_MAJOR 1
#DEFINE WS_VERSION_MINOR 1
#DEFINE MIN_SOCKETS_REQD 1
#DEFINE SOCKET_ERROR -1
#DEFINE WSADESCRIPTION_LEN 256
#DEFINE WSASYS_STATUS_LEN 128
*/--- Instrucciones DECLARE DLL para manipular Windows Sockets
Declare Integer WSAGetLastError In WSock32.Dll
Declare Integer WSAStartup In WSock32.Dll Integer wVersionRequested , String @lpWSAData
Declare Integer WSACleanup In WSock32.Dll
Declare Integer gethostname In WSock32.Dll String @lpHostName, Integer iHostNameLenght
Declare Integer gethostbyname In WSock32.Dll String lpHostName
Declare RtlMoveMemory In Win32API String @lpDest, Integer nSource, Integer nBytes
*/--- Valores
lcResult = ''
lpHostName = Space(256)
lnHostEnt_Addr = 0
lnHostEnt_Lenght = 0
lnHostEnt_AddrList = 0
lnHostIp_Addr = 0
lpTempIp_Addr = Chr(0)
lpHostIp_Addr = Replicate(Chr(0), 4)
lpWSHostEnt = Replicate(Chr(0), 4 + 4 + 2 + 2 + 4)
lpWSAData = Replicate(Chr(0), 2 + 2 + WSADESCRIPTION_LEN + 1 + WSASYS_STATUS_LEN + 1 + 2 + 2 + 4)
*/--- Iniciar Windows Sockets
If WSAStartup(WS_VERSION_REQD, @lpWSAData) = 0
*/--- Valores
*lnVersion = CToBin(Substr(lpWSAData, 1, 2), "2RS")
*lnMaxSockets = CToBin(Substr(lpWSAData, 391, 2), "2RS")
*/--- Determinar si Windows Sockets responde
If gethostname(@lpHostName, 256) <> SOCKET_ERROR
*/--- Valores
lpHostName = Alltrim(lpHostName)
lnHostEnt_Addr = gethostbyname(lpHostName)
*/--- Determinar si Windows Sockets no dio error
If lnHostEnt_Addr <> 0
*/--- Mover bloques de memoria
RtlMoveMemory(@lpWSHostEnt, lnHostEnt_Addr, 16)
*/--- Valores
*lnHostEnt_AddrList = StrToLong(Substr(lpWSHostEnt, 13, 4))
*lnHostEnt_Lenght = StrToInt(Substr(lpWSHostEnt, 11, 2))
lnHostEnt_AddrList = CToBin(Substr(lpWSHostEnt, 13, 4), "4RS")
lnHostEnt_Lenght = CToBin(Substr(lpWSHostEnt, 11, 2), "2RS")
*/--- Obtener todas las direcciones IP de la máquina
Do While .T.
*/--- Mover bloques de memoria
RtlMoveMemory(@lpHostIp_Addr, lnHostEnt_AddrList, 4)
*/--- Valores
*lnHostIp_Addr = StrToLong(lpHostIp_Addr)
lnHostIp_Addr = CToBin(lpHostIp_Addr, "4RS")
*/--- No hay o no quedan más direcciones validas
If lnHostIp_Addr = 0
Exit
Else
*/--- Separar multiples IP`s con comas
lcResult = lcResult + Iif(Empty(lcResult), '', ',')
EndIf
lpTempIp_Addr = Replicate(Chr(0), lnHostEnt_Lenght)
*/--- Mover bloques de memoria
RtlMoveMemory(@lpTempIp_Addr, lnHostIp_Addr, lnHostEnt_Lenght)
*/--- Componer cadena IP con puntos
For lnCnt = 1 To lnHostEnt_Lenght
lcResult = lcResult + Transform(Asc(Substr(lpTempIp_Addr, lnCnt, 1))) + ;
Iif(lnCnt = lnHostEnt_Lenght, '', '.')
EndFor
*/--- Continuar con la siguiente direccion
lnHostEnt_AddrList = lnHostEnt_AddrList + 4
EndDo
*/--- Obtener solo el primer IP de la lista
lcResult = GetWordNum(lcResult, 1, ",")
EndIf
EndIf
EndIf
*/--- Parar Windows Sockets
If WSACleanup() <> 0
lcResult = ''
EndIf
*/--- Retorno
Return lcResult
EndFunc