tcp協議發送到某個地址端口號是,地址是域名3322.net類型,轉換成ip地址。親測兩種方法都可以。
1、參考https://blog.csdn.net/szsbell/article/details/51781220
///<summary> /// 傳入域名返回對應的IP ///</summary> ///<param name="domain">域名</param> ///<returns></returns> public static string getIP(string domain) { domain = domain.Replace("http://", "").Replace("https://", ""); IPHostEntry hostEntry = Dns.GetHostEntry(domain); IPEndPoint ipEndPoint = new IPEndPoint(hostEntry.AddressList[0], 0); return ipEndPoint.Address.ToString(); }
2、參考https://blog.csdn.net/u013617409/article/details/77917993
IPHostEntry hostInfo = Dns.GetHostEntry(ip); IPAddress ipAddress = hostInfo.AddressList[0];