Hi
I am trying to get the dns name from IP address and i found this code in MSDN,I am calling the below function
like
Dim strHostName=DisplayHostAddress("216.208.86.19") but getting Socket Exception,does anyone know what i am doing wrong?
Thanks
Nouman
Public Function DisplayHostAddress(ByVal IpAddressString As String) As String
Try
Dim hostIPAddress As IPAddress = IPAddress.Parse(IpAddressString)
' Call the GetHostByAddress(IPAddress) method, passing an IPAddress object as an argument
' to obtain an IPHostEntry instance, containing address information for the specified host.
Dim hostInfo As IPHostEntry = Dns.GetHostByAddress(hostIPAddress)
' Get the IP address list that resolves to the host names contained in
' the Alias property.
Dim address As IPAddress() = hostInfo.AddressList
' Get the alias names of the above addresses in the IP address list.
Dim [alias] As String() = hostInfo.Aliases
DisplayHostAddress = hostInfo.HostName
'Console.WriteLine(ControlChars.Cr + "Aliases :")
'Dim index As Integer
'For index = 0 To [alias].Length - 1
' Console.WriteLine([alias](index))
'Next index
'Console.WriteLine(ControlChars.Cr + "IP address list : ")
'For index = 0 To address.Length - 1
' Console.WriteLine(address(index))
'Next index
Catch e As SocketException
MsgBox("SocketException caught!!! " + e.Message, MsgBoxStyle.Information, strSystemTitle)
Catch e As FormatException
MsgBox("FormatException caught!!! " + e.Message, MsgBoxStyle.Information, strSystemTitle)
Catch e As ArgumentNullException
MsgBox("ArgumentNullException caught!!! " + e.Message, MsgBoxStyle.Information, strSystemTitle)
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Information, strSystemTitle)
End Try
End Function 'DisplayHostAddress
Nouman Zaheer
Software Engineer
MSR
I am trying to get the dns name from IP address and i found this code in MSDN,I am calling the below function
like
Dim strHostName=DisplayHostAddress("216.208.86.19") but getting Socket Exception,does anyone know what i am doing wrong?
Thanks
Nouman
Public Function DisplayHostAddress(ByVal IpAddressString As String) As String
Try
Dim hostIPAddress As IPAddress = IPAddress.Parse(IpAddressString)
' Call the GetHostByAddress(IPAddress) method, passing an IPAddress object as an argument
' to obtain an IPHostEntry instance, containing address information for the specified host.
Dim hostInfo As IPHostEntry = Dns.GetHostByAddress(hostIPAddress)
' Get the IP address list that resolves to the host names contained in
' the Alias property.
Dim address As IPAddress() = hostInfo.AddressList
' Get the alias names of the above addresses in the IP address list.
Dim [alias] As String() = hostInfo.Aliases
DisplayHostAddress = hostInfo.HostName
'Console.WriteLine(ControlChars.Cr + "Aliases :")
'Dim index As Integer
'For index = 0 To [alias].Length - 1
' Console.WriteLine([alias](index))
'Next index
'Console.WriteLine(ControlChars.Cr + "IP address list : ")
'For index = 0 To address.Length - 1
' Console.WriteLine(address(index))
'Next index
Catch e As SocketException
MsgBox("SocketException caught!!! " + e.Message, MsgBoxStyle.Information, strSystemTitle)
Catch e As FormatException
MsgBox("FormatException caught!!! " + e.Message, MsgBoxStyle.Information, strSystemTitle)
Catch e As ArgumentNullException
MsgBox("ArgumentNullException caught!!! " + e.Message, MsgBoxStyle.Information, strSystemTitle)
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Information, strSystemTitle)
End Try
End Function 'DisplayHostAddress
Nouman Zaheer
Software Engineer
MSR