[AccessD] Obtaining IP Address

Gustav Brock Gustav at cactus.dk
Thu Mar 22 10:14:42 CDT 2007


Hi John

It can be done as mentioned here by using an array:

http://files.codes-sources.com/fichier.aspx?id=25740&f=Module+Reseau.bas

Public Function GetIPFromHostName(ByVal sHostName As String) As String
'Recupére l'adresse IP locale avec le nom local.
Dim ptrHosent As Long
Dim ptrName As Long
Dim ptrAddress As Long
Dim ptrIPAddress As Long
Dim ptrIPAddress2 As Long

    ptrHosent = gethostbyname(sHostName & vbNullChar)

    If ptrHosent <> 0 Then
'Assign pointer addresses and offset ptrName is the official name of the host (PC).
'If using the DNS or similar resolution system, it is the Fully Qualified Domain Name (FQDN)
'that caused the server to return a reply. If using a local hosts file, it is the first
'entry after the IP address.
        ptrName = ptrHosent
      
'Null-terminated list of addresses for the host. The Address is offset 12 bytes from the start of
'the HOSENT structure. Note: Here we are retrieving only the first address returned. To return more
'than one, define sAddress as a string array and loop through the 4-byte ptrIPAddress members returned.
'The last item is a terminating null. All addresses are returned in network byte order.
        ptrAddress = ptrHosent + 12
      
'Obtient l'adresse IP.
        CopyMemory ptrName, ByVal ptrName, 4
        CopyMemory ptrAddress, ByVal ptrAddress, 4
        CopyMemory ptrIPAddress, ByVal ptrAddress, 4
        CopyMemory ptrIPAddress2, ByVal ptrIPAddress, 4

        GetIPFromHostName = GetInetStrFromPtr(ptrIPAddress2)
    End If
End Function

I've never had the need, thus I have no code for it.
Perhaps Drew will repost his VB function here?

/gustav

>>> jwcolby at colbyconsulting.com 22-03-2007 15:36 >>>
That worked.  The only issue is that there are often more than one IP
addresses and this only returns one.  My laptop for example has two, one for
the wireless connection and one for the cable connection.  But this is a
good start.

Thanks,

John W. Colby
Colby Consulting
www.ColbyConsulting.com 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com 
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Thursday, March 22, 2007 10:14 AM
To: accessd at databaseadvisors.com 
Subject: Re: [AccessD] Obtaining IP Address

Hi John

This is more convoluted than you might believe.
Here is one method: MachineHostAddress





More information about the AccessD mailing list