PDA

Click to See Complete Forum and Search --> : IP Addresses


Gazz
Nov 8th, 1999, 08:02 PM
Can someone please tell me how i would go about obtaining an IP address from a remote workstation?? Code would be appreciated, but an explanation would be ok...i think. q:->

Cheerz...Gazz

------------------
Don't let your fears stand in the way of your dreams.

smalig
Nov 8th, 1999, 08:08 PM
Look at http://www.vb-world.net/ubb/Forum1/HTML/009048.html

------------------
smalig
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)

Gazz
Nov 8th, 1999, 08:20 PM
how do i select which computers IP i want??

Gazz
Nov 8th, 1999, 08:24 PM
Also, the computer isn't recognising SocketsInitialize, as it hasn't "been defined"....... ????

(As you may have guessed, IP addreses are not my fave subject, but i have to do this..)

smalig
Nov 8th, 1999, 08:26 PM
How to display networked computers in a list box http://smalig.tripod.com/vb/119902.html

------------------
smalig
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)

Aaron Young
Nov 8th, 1999, 10:08 PM
On a Form, place 2 Textboxes and a Command Button..

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) <> 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 Command1_Click()
Text2 = GetIPAddress(Text1)
End Sub

Type the Computer Name in Text1, Press the Command Button and the IP will be displayed in Text2.

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