|
|
Title | Get a computer's IP address from its name |
Keywords | IP address, internet address |
Categories | Software 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
|
|
|
|
|
|