zoukankan      html  css  js  c++  java
  • 获取本地IP地址

    如果是双IP就不能用这种方式了 需要把ip写到配置文件中了

        public static string GetLocalIP()
            {
                try
                {
                    string IP = ConfigurationManager.AppSettings["LocalIP"];
                    if (string.IsNullOrWhiteSpace(IP))
                        return IP;
    
                    string HostName = Dns.GetHostName(); //得到主机名
                    IPHostEntry IpEntry = Dns.GetHostEntry(HostName);
                    for (int i = 0; i < IpEntry.AddressList.Length; i++)
                    {
                        //从IP地址列表中筛选出IPv4类型的IP地址
                        //AddressFamily.InterNetwork表示此IP为IPv4,
                        //AddressFamily.InterNetworkV6表示此地址为IPv6类型
                        if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                        {
                            return IpEntry.AddressList[i].ToString();
                        }
                    }
                    return "";
                }
                catch (Exception ex)
                {
                    Log.WriteLog(ex);
                    return "";
                }
            }
  • 相关阅读:
    Postgresql常用命令&&函数
    gcc g++参数
    cython编译Python为c语言
    安装python3
    pip 国内源
    ceph 对象存储s3
    Rancher基础
    helm常用命令
    chartmuseum配置和使用
    python-etcd3
  • 原文地址:https://www.cnblogs.com/yy15611/p/13371197.html
Copyright © 2011-2022 走看看