标签搜索
C#

C#域名解析ip地址

Y
Y
2020-04-22 / 0 评论 / 64 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2020年04月22日,已超过1248天没有更新,若内容或图片失效,请留言反馈。

WPF输入域名,解析出来地址
用于通过域名连接TCP/UDP服务器
核心代码:

public static string domain2ip(string domian)
        {
            try
            {
                IPHostEntry ipHostInfo = Dns.GetHostEntry(domian);
                IPAddress myip = ipHostInfo.AddressList[0];
                return myip.ToString();
            }
            catch (Exception e)
            {
                return "0.0.0.0";
            }
        }

gitee地址:https://gitee.com/ifshy/domain2ip

0

评论 (0)

取消