Getting User name & IP address 
Author Message
 Getting User name & IP address

        Does anyone know where to find current user login name & more
important, the current IP address of the current machine? I have looked
& not had much luck finding either in the registry. I figure it's
stored as a dword. Any help with this would be greatly appreciated.

P.S. Yes, I'm a Newbie! Hehheh!

Sun, 10 Jan 1999 03:00:00 GMT  
 Getting User name & IP address

>    Does anyone know where to find current user login name & more
>important, the current IP address of the current machine?

In a LAN, Internet, what? If you want to find Internet address:

Type HostEntType
    h_name As Long          'LPstr
    h_aliases As Long       'LPstr to *h_aliases
    h_addrtype As Integer   'Plain int
    h_length As Integer     'Plain int
    h_addr As Long          'LPstr
End Type

Declare Function gethostname Lib "WinSock.DLL" (ByVal host As String, ByVal
hostlen As Integer) As Integer

Declare Function gethostbyname Lib "WinSock.DLL" (ByVal host As String) As

Declare Sub hmemcpy Lib "Kernel" (hpvDest As Any, ByVal hpvSource As Any,
ByVal cbCopy&)

Function IPFromName& (ByVal ip_name$)

Dim addr As Long
Dim anIP As Long
Dim aHost As hostenttype

   '* Using the gethostbyname API,

   anIP = gethostbyname(Trim$(ip_name$))

   '* we get back a pointer to a hostent structure.
   '* If the pointer is not NULL, we were able to resolve the name into an
   '* address.
   If anIP <> 0 Then
      '* But we're not done yet.  Since the result (anIP) is a LONG POINTER

      '* to a data
      '* structure, we have to force Visual Basic to move the data pointed
      '* to by the pointer
      '* into a valid hostenttype data structure, by using the Windows
      '* hmemcpy API.

      hmemcpy aHost, anIP, Len(aHost)

      '* Now the hostenttype structure (aHost) is filled in, but we need to

      '* get the
      '* address out of the h_addr field.  The h_addr field is a POINTER to

      '* a POINTER,
      '* so we use the same hmemcpy trick to get the address of the first
      '* pointer...

      hmemcpy addr, aHost.h_addr, 4

      '* and then use it again to get to the Real Data (of length h_length)

      hmemcpy addr, addr, aHost.h_length

      '* Whew. Now we have the address stored in the variable addr.

      IPFromName& = addr

   End If

End Function

Use like this:

hostname$ = Space$(255)
retval% = gethostname(hostname$, len(hostname$))
hostname$ = Left$(hostname$, retval%)

MyIP = IpFromName(hostname$)

VB Info:
Knowledge Base:

Mon, 11 Jan 1999 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Getting a machine's MAC address given a NETBIOS machine name or IP address

2. Getting localhost name/IP address...

3. Getting host name or ip address

4. Getting a computer name from a ip address

5. Getting TCP/IP address from computer name

6. Getting computer name from ip address?

7. Getting IP Address of a user on a network

8. Getting IP address of user

9. Getting a users Ip address

10. Getting a users Ip address

11. Getting the users IP address...

12. Getting a users IP address


Powered by phpBB® Forum Software