Hello everyone. I am hoping to find and have thus far been unable to locate a solution to this problem. I have found a way to find host names on the network using specific known good IP addresses using the following code:
This finds most of the devices on my network. There is one particular device that appears to respond intermittently which is an xBox One. Is there something wrong with my code that would prevent a host name obtained by IP from being populated? I know that the device is connected and the IP is correct. Suggestions would be much appreciated!
Thank you in advance.
Code:
' start searching and logging IPs in lstIpsToSearch
' at interval specified in cboInterval
Dim outFile As IO.StreamWriter
outFile = IO.File.AppendText("SearchLog.txt")
Dim strHostName As String
For intSub As Integer = 0 To strIP.GetUpperBound(0)
Dim dtDateTime As DateTime = Now
Dim dtDate As String = FormatDateTime(dtDateTime, DateFormat.LongDate)
Dim tmTime As String = FormatDateTime(dtDateTime, DateFormat.LongTime)
Try
strHostName = System.Net.Dns.GetHostEntry(strIP(intSub)).HostName.ToString
Catch ex As Exception
strHostName = Nothing
End Try
' search for IP host name
If strHostName <> Nothing Then
' log successful search
outFile.WriteLine("IP " & strIP(intSub).PadRight(20) & " found at " & tmTime.PadRight(15) & " on " & dtDate.PadLeft(30) & " with host name " & strHostName)
Else
' do nothing; if no host name no sense in logging
End If
Next intSub
outFile.Close()
Thank you in advance.