我正在嘗試使TCP套接字連接到IP地址。我可以直接解析IP地址,這樣做:在C#中解析來自DNS的IP地址
IPAddress ipAddress = IPAddress.Parse("192.168.1.123");
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 80);
// Create a TCP/IP socket.
Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // This works!
但是,我無法弄清楚如何從DNS字符串神聖該IP地址。我試過下面的每個組合:
IPAddress ipAddress = Dns.Resolve("www.mydns.org"); // No dice
IPAddress ipAddress = Dns.GetHostEntry("www.mydns.org"); // Nada
IPAddress ipAddress = IPAddress.Parse(Dns.Resolve("www.mydns.org")); // So many errors...
IPAddress ipAddress = IPAddress.Parse(Dns.Resolve("www.mydns.org").toString()); // WTh is this attempt anyway?
你們有一種靈魂有一個提示,以幫助我擠一個ip地址了DNS的?
你的先生,是一個精靈。謝謝。 – Nanomurf