PDA

Click to See Complete Forum and Search --> : How do I make VB determine the users computers' current IP?


Pikachu_902
Dec 7th, 1999, 09:53 PM
How do I make VB determine the users computers' current IP?

Aaron Young
Dec 7th, 1999, 09:55 PM
The easiest eay is probably to place the Winsock Control on your Form and look at the LocalIP Property.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Pikachu_902
Dec 7th, 1999, 10:03 PM
That doesnt work
I need more info
I don't know how to do that
I have a winsock control though

onerrorgoto
Dec 7th, 1999, 10:06 PM
Maybe one of these topics can help you
<A HREF="http://www.vb-world.net/ubb/Forum1/HTML/009169.html" TARGET=_blank>http://www.vb-world.net/ubb/Forum1/HTML/009169.html
</A> <A HREF="http://www.vb-world.net/ubb/Forum1/HTML/009536.html" TARGET=_blank>http://www.vb-world.net/ubb/Forum1/HTML/009536.html
</A> <A HREF="http://www.vb-world.net/ubb/Forum1/HTML/007469.html" TARGET=_blank>http://www.vb-world.net/ubb/Forum1/HTML/007469.html
</A> <A HREF="http://www.vb-world.net/ubb/Forum1/HTML/006559.html" TARGET=_blank>http://www.vb-world.net/ubb/Forum1/HTML/006559.html
</A> <A HREF="http://www.vb-world.net/ubb/Forum1/HTML/006559.html" TARGET=_blank>http://www.vb-world.net/ubb/Forum1/HTML/006559.html
</A>

I found them searchin this BB for computer IP

------------------
On Error Goto Bed :0)
anders@zsystemdesign.se


[This message has been edited by onerrorgoto (edited 12-08-1999).]

[This message has been edited by onerrorgoto (edited 12-08-1999).]

[This message has been edited by onerrorgoto (edited 12-08-1999).]

[This message has been edited by onerrorgoto (edited 12-08-1999).]

Aaron Young
Dec 7th, 1999, 10:38 PM
Place the Winsock Control on your Form then in the Forms Load Event..

Private Sub Form_Load()
Caption = Winsock1.LocalIP
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Aaron Young
Dec 8th, 1999, 12:19 AM
If you still insist that doesn't work, you can do it the long way using the Winsock DLL APIs..

Private Const MAX_WSADescription = 256
Private Const MAX_WSASYSStatus = 128
Private Const WS_VERSION_REQD = &H101

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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHost As String) 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 Function GetIPAddress(ByVal sHost As String) As String

Dim I As Integer
Dim lHost As Long
Dim lIP As Long
Dim sIP() As Byte
Dim sFullIP As String
Dim tHost As HOSTENT
Dim tSocket As WSADATA

'Establish an Open Socket
If WSAStartup(WS_VERSION_REQD, tSocket) &lt;&gt; 0 Then Exit Function

'Attempt to Locate Data pointer for Specified Host Name
lHost = gethostbyname(sHost)

If lHost = 0 Then
MsgBox "Unable to Locate Host."
Else
'Get the Host Info
CopyMemory tHost, lHost, Len(tHost)
'Extract the Address of the IP Data from the Addresslist Pointer
CopyMemory lIP, tHost.hAddrList, Len(tHost.hAddrList)
'Build a Tempory array to hold the IP Values
ReDim sIP(tHost.hLen - 1)
'Copy the IP Values into the Array
CopyMemory sIP(0), lIP, tHost.hLen
'Build the IP Address
For I = 0 To tHost.hLen - 1
sFullIP = sFullIP & "." & sIP(I)
Next
'Trim of the Preceeding Period
GetIPAddress = Mid(sFullIP, 2)
End If

'Close up the Socket
Call WSACleanup

End Function

Private Sub Form_Load()
Caption = GetIPAddress("")
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net