Obtener los IP de las PC de una LAN

09/11/2004 - 23:18 por Jesus Hurtado | Informe spam
Como podría obtener las direcciones IP y los nombres de los PC que estan
conectados a internet dentro de una LAN, como en cabinas de Internet ???
Por ejemplo, esto me serviría para controlar el tiempo que una PC puede
navegar y luego poder enviarle un mensaje... o hacer otros trabajos con
ese dato.

Gracias por la colaboración.

JHurtado.




-
PortalFox :: Nada corre como un zorr
http://www.portalfox.co

PortalFox - NNTP Forum Gatewa

Preguntas similare

Leer las respuestas

#1 Juany
12/11/2004 - 18:34 | Informe spam
Function Obtener_IP
#Define WSADATA_SIZE 398
#Define WS_VERSION 514
#Define HOSTBUFFER_SIZE 256
#Define HOSTENT_STRUCT_SIZE 16
cIP = ""

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)
cIP = IPPortion(lnResult)
Endif
Endif
Endif

If Empty(lcMessage) or Empty(cIP)
lcMessage = "No se pudo obtener Host - IP"
Messagebox(lcMessage,64,"Local Host & IP")
cIP="0.0.0.0"
EndIf

* Messagebox(lcMessage,64,"Local Host & IP")

=WSACleanup()
Else
Messagebox("Error : " + Transform(lnResult))
ENDIF
Return cIP
EndFunc
**************************
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


-
PortalFox :: Nada corre como un zorr
http://www.portalfox.co

PortalFox - NNTP Forum Gatewa
Respuesta Responder a este mensaje
#2 Baltazar Ramirez
04/01/2005 - 19:57 | Informe spam
Hola Juany, corri tu codigo y no hace nada, podrias ayudarme por favor ?

"Juany" wrote in message
news:
Function Obtener_IP
#Define WSADATA_SIZE 398
#Define WS_VERSION 514
#Define HOSTBUFFER_SIZE 256
#Define HOSTENT_STRUCT_SIZE 16
cIP = ""

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)
cIP = IPPortion(lnResult)
Endif
Endif
Endif

If Empty(lcMessage) or Empty(cIP)
lcMessage = "No se pudo obtener Host - IP"
Messagebox(lcMessage,64,"Local Host & IP")
cIP="0.0.0.0"
EndIf

* Messagebox(lcMessage,64,"Local Host & IP")

=WSACleanup()
Else
Messagebox("Error : " + Transform(lnResult))
ENDIF
Return cIP
EndFunc
**************************
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



PortalFox :: Nada corre como un zorro
http://www.portalfox.com

PortalFox - NNTP Forum Gateway
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida