Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

vb.net gethostbyaddress help

This function returns a host name by ipaddress. But the problem i have is that if there is no host at a given IP address it takes a long time for it to time out. is there any way to force it to time out in say 3 seconds if it does not find a host at the given address?
thanks
Scott

Public Function iptohost(ByVal ip As String)

Dim dns As System.Net.Dns
Dim address As System.Net.IPHostEntry
Try
address = dns.GetHostByAddress(ip)
iptohost = address.HostName

Catch e As SocketException
MsgBox("SocketException caught!!!")
MsgBox(("Source : " + e.Source))
MsgBox(("Message : " + e.Message))

Catch e As FormatException
MsgBox("FormatException caught!!!")
MsgBox(("Source : " + e.Source))
MsgBox(("Message : " + e.Message))

Catch e As ArgumentNullException
MsgBox("ArgumentNullException caught!!!")
MsgBox(("Source : " + e.Source))
MsgBox(("Message : " + e.Message))

Catch e As Exception
MsgBox("Exception caught!!!")
MsgBox(("Source : " + e.Source))
MsgBox(("Message : " + e.Message))

End Try

End Function
[1146 byte] By [sradel] at [2007-11-11 6:42:13]