Finding network names

  • Thread starter Thread starter Martin Racette
  • Start date Start date
M

Martin Racette

Hi,

I'm making am app that check which IP is currently use on my network, but I
would like to be able to find out the name of the computer to whom the IP
belong, and I can not find out how to do it using VB Express 2005
 
Martin Racette said:
Hi,

I'm making am app that check which IP is currently use on my network, but I
would like to be able to find out the name of the computer to whom the IP
belong, and I can not find out how to do it using VB Express 2005

--
Thank You in Advance
Merci a l'avance

Martin
Please have a look at the class System.Net.DNS. If you use the function
GetHostEntry you get an IPHostEntry. The property 'HostName' (of the
IPHostEntry) should be the value that you are looking for.
If you prefer to put this functionality into an own thread, you can use
BeginGetHostEntry and EndGetHostEntry instead.
 
Thank you for the information, but I do not how I can pass the IP address
so that can find out the name that is associated with it

If you could clarify how to build such a function I would appreciated.

BTW I did check the online help, and I just get more confuse by it
 
Martin Racette said:
Thank you for the information, but I do not how I can pass the IP address
so that can find out the name that is associated with it

If you could clarify how to build such a function I would appreciated.

BTW I did check the online help, and I just get more confuse by it
Ok, I have just done a little coding. To run it, you'll need a form and a
button (form1 and button1).

Imports System.Net

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'With the next line you choose the IP address you want to test.
Dim myBytes() As Byte = {192, 168, 0, 241}
Dim TestIP As New IPAddress(myBytes)
Dim msg As String = ""
Dim ComputerName As String = ""
ComputerName = IP_to_Name(TestIP)
Select Case ComputerName.Length
Case 1 To 99
msg = "The computer with the IP Address " & TestIP.ToString
& " is named : " & ComputerName
Case 0
msg = "IP Address " & TestIP.ToString & " is not online at
the moment."
End Select
MsgBox(msg)
End Sub

Private Function IP_to_Name(ByVal an_IP_address As IPAddress) As String
Try
Return Dns.GetHostEntry(an_IP_address).HostName
Catch ex As Exception
'MsgBox(ex.ToString)
Return ""
End Try
End Function

End Class
 
Back
Top