Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Como obtener la ip con VB 6???

Estas en el tema de Como obtener la ip con VB 6??? en el foro de Visual Basic clásico en Foros del Web. Hola.. me pueden decir como se puede obtener la dirección ip con VB6?? Saludos y gracias...
  #1 (permalink)  
Antiguo 03/03/2005, 07:33
Avatar de Sir Matrix  
Fecha de Ingreso: octubre-2000
Ubicación: Dentro de mi cabeza. ono?
Mensajes: 1.264
Antigüedad: 23 años, 6 meses
Puntos: 3
Como obtener la ip con VB 6???

Hola..

me pueden decir como se puede obtener la dirección ip con VB6??

Saludos y gracias
__________________
|||| ))>_<(( ||||
www.webmagic.cl <-- esta pagina está mala, no la busquen
  #2 (permalink)  
Antiguo 03/03/2005, 08:57
Avatar de jrp01  
Fecha de Ingreso: mayo-2004
Ubicación: México
Mensajes: 2.702
Antigüedad: 19 años, 11 meses
Puntos: 0
La IP de tu maquina?
  #3 (permalink)  
Antiguo 03/03/2005, 09:18
Avatar de Sir Matrix  
Fecha de Ingreso: octubre-2000
Ubicación: Dentro de mi cabeza. ono?
Mensajes: 1.264
Antigüedad: 23 años, 6 meses
Puntos: 3
La ip de la màquina que ejecuta el ejecutable :P
__________________
|||| ))>_<(( ||||
www.webmagic.cl <-- esta pagina está mala, no la busquen
  #4 (permalink)  
Antiguo 03/03/2005, 10:37
Avatar de jrp01  
Fecha de Ingreso: mayo-2004
Ubicación: México
Mensajes: 2.702
Antigüedad: 19 años, 11 meses
Puntos: 0
Tienes un programa para cliente y otro para servidor?
  #5 (permalink)  
Antiguo 03/03/2005, 13:01
Avatar de vbx3m  
Fecha de Ingreso: febrero-2005
Ubicación: Venezuela
Mensajes: 524
Antigüedad: 19 años, 2 meses
Puntos: 1
Direccion IP

Tengo este codigo que tambien sirve para conocer el nombre del host... Es algo largo:

Private Const MAX_WSADescription = 256
Private Const MAX_WSASYSStatus = 128
Private Const ERROR_SUCCESS As Long = 0
Private Const WS_VERSION_REQD As Long = &H101
Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
Private Const MIN_SOCKETS_REQD As Long = 1
Private Const SOCKET_ERROR As Long = -1
Private Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLen As Integer
hAddrList As Long
End Type
Private Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription(0 To MAX_WSADescription) As Byte
szSystemStatus(0 To MAX_WSASYSStatus) As Byte
wMaxSockets As Integer
wMaxUDPDG As Integer
dwVendorInfo As Long
End Type
Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal szHost As String, ByVal dwHostLen As Long) As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHost As String) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)

Public Function HiByte(ByVal wParam As Integer)
HiByte = wParam \ &H100 And &HFF&
End Function

Public Function LoByte(ByVal wParam As Integer)
LoByte = wParam And &HFF&
End Function

Public Function SocketsInitialize() As Boolean
Dim WSAD As WSADATA
Dim sLoByte As String
Dim sHiByte As String
If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
MsgBox "The 32-bit Windows Socket is not responding."
SocketsInitialize = False
Exit Function
End If
If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
MsgBox "This application requires a minimum of " & _
" CStr(MIN_SOCKETS_REQD) & ` supported sockets."
SocketsInitialize = False
Exit Function
End If
If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or _
(LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And _
HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
sHiByte = CStr(HiByte(WSAD.wVersion))
sLoByte = CStr(LoByte(WSAD.wVersion))
MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
" is not supported by 32-bit Windows Sockets."
SocketsInitialize = False
Exit Function
End If
SocketsInitialize = True
End Function

Public Sub SocketsCleanup()
If WSACleanup() <> ERROR_SUCCESS Then
MsgBox "Socket error occurred in Cleanup."
End If
End Sub

Public Function GetIPAddress() As String
Dim sHostName As String * 256
Dim lpHost As Long
Dim HOST As HOSTENT
Dim dwIPAddr As Long
Dim tmpIPAddr() As Byte
Dim i As Integer
Dim sIPAddr As String
If Not SocketsInitialize() Then
GetIPAddress = ""
Exit Function
End If
If gethostname(sHostName, 256) = SOCKET_ERROR Then
GetIPAddress = ""
MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
" has occurred. Unable to successfully get Host Name."
SocketsCleanup
Exit Function
End If
sHostName = Trim$(sHostName)
lpHost = gethostbyname(sHostName)

If lpHost = 0 Then
GetIPAddress = ""
MsgBox "Windows Sockets are not responding. " & _
"Unable to successfully get Host Name."
SocketsCleanup
Exit Function
End If
CopyMemory HOST, lpHost, Len(HOST)
CopyMemory dwIPAddr, HOST.hAddrList, 4
ReDim tmpIPAddr(1 To HOST.hLen)
CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen
For i = 1 To HOST.hLen
sIPAddr = sIPAddr & tmpIPAddr(i) & "."
Next
GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
SocketsCleanup

End Function

Private Sub Form_Load()
Text1.Text = GetIPAddress
End Sub

Espero que te sirva... Cualquier cosa me avisas...
__________________
ホルヘ・ラファエル・マルティネス・レオン
  #6 (permalink)  
Antiguo 03/03/2005, 14:26
 
Fecha de Ingreso: marzo-2005
Mensajes: 5
Antigüedad: 19 años, 1 mes
Puntos: 0
Obtener IP de forma sencilla

Hola, para conocer tu dirección IP local, crea un proyecto, en un form incluye un control WinSock y luego pones el código en el load del form:

WinSock1.RemoteHost = WinSock1.LocalHostName
MsgBox WinSock1.LocalIP

Y con esto debe mostrarte tú IP.
  #7 (permalink)  
Antiguo 09/03/2011, 20:01
 
Fecha de Ingreso: marzo-2011
Mensajes: 2
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: Como obtener la ip con VB 6???

Esta funcion jalo de pelos y es muy diferente a esta otra que encontre...

Const MAX_IP = 5
Type IPINFO
dwAddr As Long
dwIndex As Long
dwMask As Long
dwBCastAddr As Long
dwReasmSize As Long
unused1 As Integer
unused2 As Integer
End Type
Type MIB_IPADDRTABLE
dEntrys As Long
mIPInfo(MAX_IP) As IPINFO
End Type
Type IP_Array
mBuffer As MIB_IPADDRTABLE
BufferLen As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
Public Const MAX_COMPUTERNAME_LENGTH As Long = 31
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function ConvertAddressToString(longAddr As Long) As String
Dim myByte(3) As Byte
Dim Cnt As Long
CopyMemory myByte(0), longAddr, 4
For Cnt = 0 To 3
ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
Next Cnt
ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
End Function
Public Function GetWanIP() As String
Dim ret As Long, Tel As Long
Dim bBytes() As Byte
Dim TempList() As String
Dim TempIP As String
Dim Tempi As Long
Dim Listing As MIB_IPADDRTABLE
Dim L3 As String
On Error GoTo END1
GetIpAddrTable ByVal 0&, ret, True
If ret <= 0 Then Exit Function
ReDim bBytes(0 To ret - 1) As Byte
ReDim TempList(0 To ret - 1) As String
GetIpAddrTable bBytes(0), ret, False
CopyMemory Listing.dEntrys, bBytes(0), 4
For Tel = 0 To Listing.dEntrys - 1
CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
TempList(Tel) = ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr )
Next Tel
TempIP = TempList(0)
For Tempi = 0 To Listing.dEntrys - 1
L3 = Left(TempList(Tempi), 3)
If L3 <> "169" And L3 <> "127" And L3 <> "192" Then
TempIP = TempList(Tempi)
End If
Next Tempi
GetWanIP = TempIP
Exit Function
END1:
GetWanIP = ""
End Function

Private Sub Obten_ip_Nombre_maquina_de_red()

Dim dwLen As Long
Dim strString As String

dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String(dwLen, "X")
GetComputerName strString, dwLen
strString = Left(strString, dwLen)
NombreMaquina = strString
NumeroIP = GetWanIP

MsgBox NumeroIP

End Sub

vbx3m podrias pasarme un manual para saber como hacer este tipo de funciones....


Saludos!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:38.