MNVR
MNVR

Reputation: 875

A socket operation was attempted to an unreachable network

I am trying to validate email domain validation using the following code (Found on Code Proejct)

string hostName="<hostName>"; //Ex: yahoo.com
IPHostEntry Iphost=Dns.GetHostEntry(hostName);
IPEndPoint endPt=new IPEndPoint(Iphost.AddressList[0],25);
Socket s=new Socket(endPt.AdressFamily, SocketType.Stream, ProtocolType.Tcp);

s.Connect(endPt);

At s.Connect I am getting the error: A socket operation was attempted to an unreachable network. What might be the possible reasons and how can I resolve them? I have Firewall (Comodo) on my machine.

Upvotes: 4

Views: 8379

Answers (1)

Ian Boyd
Ian Boyd

Reputation: 256741

The computer is not able to connect to the address that was resolved.

Look at the address you were given by Dns.Resolve.

Note: The Resolve method is obsolete, and replaced with GetHostEntry. e.g.:

IPHostEntry host = Dns.GetHostEntry("yahoo.com");

Upvotes: 1

Related Questions