Nombre de Servidor

Hola a todos!!!!
Como hago para averiguar el nombre del servidor que hay en una red, es decir, el nombre de la maquina a la cual estoy conectado.
Si mi pregunta no es clara por favor hacer el comentario
Gracias

1 respuesta

Respuesta
1
Aqui tienes, espero te sea de utilidad
*| --------------------------------------------------------
*| Searcher of the address IP and address of Internet using Winsock.
*| Mexican production for the international community.
*| Programmer of systems. Lic. Ramón Rodríguez Martínez.
*|
*| --------------------------------------------------------
*| struct HOSTENT {
*| char FAR * h_name; 0:4
*| char FAR * FAR * h_aliases; 4:4
*| short h_addrtype; 8:2
*| short h_length; 10:2
*| char FAR * FAR * h_addr_list; 12:4
*| }; total = 16 bytes
#DEFINE HOSTENT_SIZE 16
*-- Clear Windows screen
Clear
DO decl
Activate Screen
IF Not InitWinsock()
RETURN
ENDIF
LOCAL lcSourceHost, lnHostAddr, lcHOSTENT, lnNamePtr, lnAddrlistPtr
*lcSourceHost = "localhost"
*lcSourceHost = "aol.com"
*lcSourceHost = "microsoft.com"
*lcSourceHost = "google.com"
* Honestly, I have no idea who are these guys below
* they just exist and all of`em sound great as for the Friday night
*
*lcSourceHost = "takeiteasy.com"
*lcSourceHost = "nevermind.com"
*lcSourceHost = "cheerup.com"
*lcSourceHost = "drink2me.com"
*lcSourceHost = "169.254.184.105"
lcSourceHost = "servidorcesa"
* retrieving an address for the HOSTENT structure
lnHostAddr = gethostbyname(lcSourceHost)
IF lnHostAddr <> 0
* retrieving and displaying the HOSTENT data
* copying data from the structure to a VFP string
lcHOSTENT = GetMemBuf (lnHostAddr, HOSTENT_SIZE)
* a pointer to the host name
lnNamePtr = buf2dword(SUBSTR(lcHOSTENT, 1,4))
? "Host name:", GetMemStr(lnNamePtr)
* a pointer to a null-terminated list of addresses
lnAddrlistPtr = buf2dword(SUBSTR(lcHOSTENT, 13,4))
* displaying IP addresses for this host
= DisplayIPs (lnAddrlistPtr)
ENDIF
* terminating use of the Ws2_32.dll
= WSACleanup()
* End of Main
PROCEDURE DisplayIPs (lnAddrlistPtr)
* retrieving IP addresses from the list
LOCAL lnElementPtr, lnIPcount, lcDataAddress, lnDataAddress,;
lcIPAddrBuf
lnIPcount = 0 && list elements retrieved
lnElementPtr = lnAddrlistPtr && first member on the list
* scanning the list one member by another
* until a null member found
DO WHILE .T.
* the list member contains a DWORD address of its data
lcDataAddress = GetMemBuf (lnElementPtr, 4)
lnDataAddress = buf2dword(lcDataAddress)
* the result -- lnDataAddress -- is an address
* to DWORD IP address for this host
IF lnDataAddress = 0
* the last member on this list is null
EXIT
ENDIF
* retrieving a DWORD with an IP address
lcIPAddrBuf = GetMemBuf (lnDataAddress, 4)
lnIPcount = lnIPcount + 1
? "IP " + LTRIM(STR(lnIPcount)) + ":",;
GetIPAddress(lcIPAddrBuf)
* shifting to the next element on the list
lnElementPtr = lnElementPtr + 4 && DWORD
ENDDO
RETURN
FUNCTION InitWinsock()
* Initializing the Winsock service for the application
#DEFINE WSADATA_SIZE 398
#DEFINE WS_VERSION 514 && 0x0202
LOCAL lcWSADATAln, lnInitResult
lcWSADATA = Repli(Chr(0), WSADATA_SIZE)
lnInitResult = WSAStartup (WS_VERSION, @lcWSADATA)
RETURN (lnInitResult = 0)
FUNCTION GetMemStr (lnAddr)
* returning data from a memory block as a VFP string
#DEFINE MEMSTR_BUFSIZE 255
LOCAL lcBuffer
lcBuffer = SPACE(MEMSTR_BUFSIZE)
= Heap2Str (@lcBuffer, lnAddr, MEMSTR_BUFSIZE)
RETURN SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)
FUNCTION GetMemBuf (lnAddr, lnBufsize)
LOCAL lcBuffer
lcBuffer = Repli(Chr(0), lnBufsize)
= Heap2Str (@lcBuffer, lnAddr, lnBufsize)
RETURN lcBuffer
FUNCTION GetIPAddress (lcAddrBuf)
* converting 4-characters string buffer
* to string representation of the IP address
LOCAL lcResult, ii
lcResult = ""
FOR ii=1 TO 4
Lc

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas