PDA

Click to See Complete Forum and Search --> : Question to Smalig and other network experts.


Pyro13
Nov 7th, 1999, 02:43 AM
you seem to know a hell of alot about VB and networks is there any way to put a Host name in a text box and get the IP in annother?

if so please tell where i can find source. thanks in advaced.


:) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :( :) :(

------------------
[]D Y R o

Aaron Young
Nov 7th, 1999, 05:54 AM
No problem, here's an example I put together using the Winsock APIs:

In a Form with 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

Just put the Host/Computer Name in Text1, press the Command Button and the IP will be placed in Text2.

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

Pyro13
Nov 8th, 1999, 04:13 AM
OK i got all the code right but it says that WSADATA is an inside outside procedure and I don't have winsock my the way. My copy of VB isn't exactly "legal" or registered or paid for so i don't know if that might have anything to do with it. If you know how i can fix that little err then thanks in advanced. :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :( :) :( :) :) :

Gimpster
Nov 8th, 1999, 04:24 AM
Aaron, I was wondering if it would be possible to use the code you gave to "sniff" IP's over the internet? Would you need to tweak it, or would it simply be too difficult to create a program to do that?

------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046

Compwiz
Nov 8th, 1999, 05:18 AM
Pyro13: You should still have WSOCK32.DLL even though you have a warez version (don't worry I won't tell anyone :)). Are you sure you typed it in exactly:

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

------------------
Tom Young, 14 Year Old
tyoung@stny.rr.com
ICQ: 15743470
AIM: TomY10
PERL, JavaScript and VB Programmer

Pyro13
Nov 10th, 1999, 06:50 AM
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)

There is an block if without end if in that part of the code you gave me.