Obtiene el Host y la IP de un equipo a través del API
#Define
WSADATA_SIZE 398
#Define
WS_VERSION 514
#Define
HOSTBUFFER_SIZE 256
#Define
HOSTENT_STRUCT_SIZE 16
Do DeclareAPIs
Local lcBuffer, lnResult, lcHostname,
lcMessage, lcHostentStruct
lcBuffer = SPACE(WSADATA_SIZE)
lnResult = WSAStartup(WS_VERSION, @lcBuffer)
lcMessage = ""
If lnResult = 0
lcBuffer = Replicate(CHR(0),HOSTBUFFER_SIZE)
lnResult = gethostname(@lcBuffer,HOSTBUFFER_SIZE)
If
lnResult = 0
lcHostname = STRTRAN(lcBuffer,CHR(0),"")
lcMessage = "HOST: "
+ lcHostname +
Chr(13)
lnResult = gethostbyname(lcHostname)
If
lnResult != 0
lcHostentStruct = MemoryBuffer(lnResult, HOSTENT_STRUCT_SIZE)
lnResult = buf2dword(Substr(lcHostentStruct,
13,4))
If
lnResult != 0
lcMessage = lcMessage +
"LOCAL IP ADDRESS: "
+ IPPortion(lnResult)
Endif
Endif
Endif
If Empty(lcMessage)
lcMessage = "Lo se
pudo obtener Host - IP"
EndIf
Messagebox(lcMessage,64,"Local
Host & IP")
=WSACleanup()
Else
Messagebox("Error
: " +
Transform(lnResult))
ENDIF
**************************
PROCEDURE DeclareAPIs
**************************
Declare Integer
WSAStartup
In
wsock32;
Integer
wVerRq,
String
@lpWSAData
Declare Integer WSACleanup In wsock32
Declare Integer
gethostname
In
wsock32;
String
@Name,
Integer
namelen
Declare Integer
gethostbyname
In
wsock32;
String HostName
Declare RtlMoveMemory
In
kernel32
As
Heap2Str;
String
@,
Integer,
Integer
Endproc
**************************
Function IPPortion(nPointer)
**************************
Local
lnAddress, lcResult
lnAddress = buf2dword(MemoryBuffer(nPointer, 4))
Return Iif(lnAddress
<> 0, JustIP(MemoryBuffer(lnAddress, 4)),
"")
Endfunc
**************************
Function JustIP(cBuffer)
**************************
Local
lcResult, lnCounter
lcResult = ""
For
lnCounter=1
To
4
lcResult = lcResult +
Ltrim(Str(Asc(Substr(cBuffer,
lnCounter)))) + Iif(lnCounter=4,
"",".")
Endfor
Return lcResult
Endfunc
**************************
Function buf2word (cBuffer)
**************************
Return Asc(Substr(cBuffer,
1,1)) + Asc(Substr(cBuffer,
2,1)) * 256
Endfunc
**************************
Function buf2dword(cBuffer)
**************************
Return Asc(Substr(cBuffer,
1,1)) + ;
BitLShift(Asc(Substr(cBuffer,
2,1)), 8) +;
BitLShift(Asc(Substr(cBuffer,
3,1)), 16) +;
BitLShift(Asc(Substr(cBuffer,
4,1)), 24)
Endfunc
**************************
Function MemoryBuffer(nAddress,
nBuffersize)
**************************
Local
lcBuffer
lcBuffer = SPACE(nBuffersize)
= Heap2Str (@lcBuffer, nAddress, nBuffersize)
Return
lcBuffer
Endfunc
Si tienes inquietudes, sígueme en Twitter para contactarme.
Seguir a @davamadort¿Deseas que tu sitio web aparezca en buscadores como google, yahoo, msn?
Contrata un plan de hosting en www.winnethost.com y recibes totalmente gratis el registro de tu sitio web en más de 24 buscadores, entre ellos google, yahoo, msn
El Sitio La Web de Davphantom se encuentra hospedado en WinNetHost.com