Muchas gracias a todos los que han respondido a mi pregunta, en especial
a "Pere" que me ha encaminado a la solución del problema.
El problema era que tengo dos protocolos TCP/IP en mi PC, uno para la
ethernet con ip fija y otro para el módem (ip dinámica).
Con cualquiera de los dos me puedo conectar al servidor Unix, y lo que
me interesaba saber era la ip de mi PC en ese momento (la que estaba
usando: la fija o la dinámica).
Con el control Winsock y su propiedad LocalIP obtenía el resultado
esperado cuando solo tenía un protocolo TCP/IP en el PC, pero cuando
tenía mas de uno ya me daba cualquier cosa.
Pero gracias a la ayuda de "Pere" que me pasó la dirección:
http://www.somser.com
en la que se encuentran excelentes trucos para VB, pude obtener lo que
precisaba:
Acá va el código fuente, ya que el que estaba en somser le faltaba algún
detalle:
Agregar un Módulo:
'***************************************************************************
'Windows API/Global Declarations for :Getting IP with VB4
'***************************************************************************
Public Const WS_VERSION_REQD = &H101
Public Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Public Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Public Const MIN_SOCKETS_REQD = 1
Public Const SOCKET_ERROR = -1
Public Const WSADescription_Len = 256
Public Const WSASYS_Status_Len = 128
Public Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type
Public Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type
Public Declare Function WSAGetLastError Lib _
"WSOCK32.DLL" () As Long
Public Declare Function WSAStartup Lib _
"WSOCK32.DLL" (ByVal wVersionRequired&, _
lpWSAData As WSADATA) As Long
Public Declare Function WSACleanup Lib _
"WSOCK32.DLL" () As Long
Public Declare Function gethostname Lib _
"WSOCK32.DLL" (ByVal hostname$, HostLen&) As Long
Public Declare Function gethostbyname Lib _
"WSOCK32.DLL" (ByVal hostname$) As Long
Public Declare Sub RtlMoveMemory Lib _
"KERNEL32" (hpvDest As Any, ByVal hpvSource&, ByVal cbCopy&)
'***************************************************************************
' Name: Getting IP with VB4
' Description:Get your IP address.I've been trying to trim this t
' o get only the IP number and get rid of any non-essential code fo
' r doing that. If anyone can help me hack this into shape, I'd rea
' lly appreciate it. moonboots@earthling.net
'boots
' By: Newsgroup Posting
'
' Inputs:None
' Returns:None
' Assumes:None
' Side Effects:None
'
'Code provided by Planet Source Code(tm) 'as is', without
' warranties as to performance, fitness, merchantability,
' and any other warranty (whether expressed or implied).
'***************************************************************************
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
********************************************************************
Agregar un form:
Option Explicit
Sub Form_Load()
' 'Sockets Initialize
Dim WSAD As WSADATA
Dim iReturn As Integer
Dim sLowByte As String, sHighByte As String, sMsg As String
iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
If iReturn <> 0 Then
MsgBox "Winsock.dll is not responding."
End
End If
If lobyte(WSAD.wversion) < WS_VERSION_MAJOR _
Or (lobyte(WSAD.wversion) = WS_VERSION_MAJOR _
And hibyte(WSAD.wversion) < WS_VERSION_MINOR) Then
sHighByte = Trim$(Str$(hibyte(WSAD.wversion)))
sLowByte = Trim$(Str$(lobyte(WSAD.wversion)))
sMsg = "Windows Sockets version " & sLowByte & "." & _
sHighByte
sMsg = sMsg & " is not supported by winsock.dll "
MsgBox sMsg
End
End If
If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
sMsg = "This application requires a minimum of "
sMsg = sMsg & Trim$(Str$(MIN_SOCKETS_REQD)) _
& " supported sockets."
MsgBox sMsg
End
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' 'Sockets Cleanup
Dim lReturn As Long
lReturn = WSACleanup()
If lReturn <> 0 Then
MsgBox "Socket error " & Trim$(Str$(lReturn)) & "
occurred in Cleanup "
End
End If
End Sub
Private Sub Command1_click()
Dim hostname As String * 256
Dim hostent_addr As Long
Dim host As HOSTENT
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer
Dim ip_address As String
If gethostname(hostname, 256) = SOCKET_ERROR Then
MsgBox "Windows Sockets error " &
Str(WSAGetLastError())
Exit Sub
Else
hostname = Trim$(hostname)
End If
hostent_addr = gethostbyname(hostname)
If hostent_addr = 0 Then
MsgBox "Winsock.dll is not responding."
Exit Sub
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4
ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
For i = 1 To host.hLength
ip_address = ip_address & temp_ip_address(i) & "."
Next
ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
MsgBox hostname
MsgBox ip_address
End Sub
***********************************************************************
Nuevamente, muchas gracias a todos y quedo a las órdenes para cualquier
consulta que quieran realizar:
Sergio Maestri
Montevideo - Uruguay
>
>Hola listeros:Como puedo obtener desde Visual Basic 5, la direcci=F3n
i=
>p
>de mi PC.
>Se que el comando winipcfg me lo dice, pero: =BFc=F3mo lo hace? ya que
>necesito el dato dentro de un programa VB.
>Adem=E1s hay que tener en cuenta que mi PC no tiene direcci=F3n ip
fija=
>,
>sino que se la asigna el servidor al que me conecto (Unix).
>Muchas gracias de antemanoSaludosSergio MaestriMontevideo Uruguay