Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Here's Code to Resolve Domain Name from IP Address

8 views
Skip to first unread message

Gerry Hull

unread,
Oct 13, 1997, 3:00:00 AM10/13/97
to

Enjoy!

Option Explicit
'DNS Resolution in VB5
'By Gerry Hull, MCP, Hull Computer Consulting
'win...@inetmarket.com
'
'GET the WINSOCK.BAS file from
http://www.apexsc.com/vb/ftp/misc/winsock.bas
'and add it to your project.

'API declares (some modified to fit this purpose)
Declare Function lstrcpynPtr Lib "kernel32" Alias "lstrcpynA" (ByVal
lpString1 As String, ByVal SrcPtr As Long, ByVal iMaxLength As Long) As
Long
Declare Function lstrlenPtr Lib "kernel32" Alias "lstrlenA" (ByVal SrcPtr
As Long) As Long
Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Src As
Any, Dest As Any, ByVal CopyLen As Long) As Long
Public Function DomainNameFromIP(ByVal IP As String) As String
Dim WSVersion As Integer 'Winsock Version
Dim hostent As hostent 'host data struct
Dim wsadata As wsadata 'Winsock info data struct
Dim IPAddress As Long 'IP address as a long
Dim Domain As String 'buffer for Domain Name String
Dim PtrHostEnt As Long 'pointer to hostent structure


Domain = "" 'initialize result
WSVersion = 1 * 256 + 1 'High byte = Major Version, low byte=Minor
Version.

If WSAStartup(WSVersion, wsadata) = 0 Then
'we started winsock ok, continue...

'now get IP address as a long in network order.
IPAddress = inet_addr(IP)
If IPAddress <> 0 Then
PtrHostEnt = gethostbyaddr(IPAddress, 4, PF_INET)
If PtrHostEnt <> 0 Then
'Copy structure to local UDT...
CopyMemory VarPtr(hostent.h_name), PtrHostEnt,
LenB(hostent)
'make sure we have a name
If hostent.h_name <> 0 Then
'make a buffer
Domain = String(512, 0)
'copy domain to string
lstrcpynPtr Domain, hostent.h_name,
lstrlenPtr(hostent.h_name)
'trim nulls
Domain = Left(Domain, InStr(Domain, Chr(0)) - 1)
End If
End If
End If

'close winsock
WSACleanUp
End If
DomainNameFromIP = Domain
End Function

chat...@gmail.com

unread,
Nov 16, 2013, 7:15:56 AM11/16/13
to
0 new messages