Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet a computer's IP address from its name
KeywordsIP address, internet address
CategoriesSoftware Engineering
 
Subroutine LocalHostName uses the gethostname function provided by WSOCK32.DLL to get the computer's name. When it starts, the program puts this name in a TextBox.

When the user clicks the button, the program uses the gethostbyname sockets API function. For details, see the code and HOWTO: Obtain the Host IP Address Using Windows Sockets.

 
' Return the local host's name.
Private Function LocalHostName() As String
Dim hostname As String * 256

    If gethostname(hostname, 256) = SOCKET_ERROR Then
        LocalHostName = "<Error>"
    Else
        LocalHostName = Trim$(hostname)
    End If
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated