PDA

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


littlejo
Jan 14th, 2000, 04:43 AM
I want to write a VB app that will run on Windows 95 that will give me the IP information (IP Address) of the client it is running or allow me to specify another client by it's computer name. Would I use Winsock, or Win32 API or what? I know that Winipcfg.exe will give me the current information of machine I'm running on, but I need to also obtain this infomation for a client I'm not running on app on. We are trying to upgrade from Static IP to DHCP. We would like to run the app from our system and specify a computer name and obtain the IP information for that system.

Thanks in advance,

Kay

Aaron Young
Jan 14th, 2000, 04:52 AM
Try this Program I wrote quite a while back using the Winsock APIs..

Add 2 Textboxes and a Command Button..

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 256) As Byte
szSystemStatus(0 To 128) 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 Const WS_VERSION_REQD = &H101

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

To use, just type the Name/URL of a PC into Text1, press the Command Button and the I.P is displayed in Text2.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com