Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why this code is raising Socket Exception?

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
CA
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
 
nomi2000,

I suspect that SocketException can assign various error codes to ErrorCode property.

You might want to look at Windows Socket Version 2 API error code documentation in MSDN.

Vladk

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top