zoukankan      html  css  js  c++  java
  • c# 得到電腦IP及電腦名


           using System.Net;

            /// <summary>
            
    /// 得到用戶電腦信息
            
    /// </summary>
            public void GetUserInfo()
            {
                
    string sIP = "";

                
    //得到計算機名 方法1
                string MachineName = System.Environment.MachineName;
                
    //得到計算機名 方法2
                string strHostName = Dns.GetHostName();

                IPAddress[] addr;

                
    //得到IP 方法1
                
    //addr = Dns.GetHostAddresses(strHostName);
                
    //得到IP 方法2
                addr = Dns.GetHostAddresses("127.0.0.1");
                
    //得到IP 方法3
                
    //addr = Dns.GetHostAddresses("localhost");

                
    //得到IP 方法4
                
    //IPHostEntry ihIP = Dns.GetHostEntry(strHostName);
                
    //addr = ihIP.AddressList;

                
    //得到IP 方法5 此句顯示老式語句警告
                addr = Dns.GetHostByName(Dns.GetHostName()).AddressList;

                
    if (addr.Length<=1)
                {
                    sIP 
    = addr[0].ToString();
                }
                
    else
                {
                    
    for (int iCount = 0; iCount < addr.Length; iCount++)
                    {
                        sIP 
    += "IP" + (iCount + 1).ToString() + ":" + addr[iCount].ToString() + " ";
                    }
                }           
            }


  • 相关阅读:
    pydoc (Development Tools) – Python 中文开发手册
    CSS :out-of-range 选择器
    wcschr (Strings) – C 中文开发手册
    gl (SGI IRIX) – Python 中文开发手册
    排版 | Typography (CSS) – Bootstrap 3 中文开发手册
    HTML 音频,视频 DOM ended 属性
    ASP.NET Web Forms 教程
    Linux 系统目录结构
    ADO Connection 对象
    JavaWeb 之 HttpServletRequest 类
  • 原文地址:https://www.cnblogs.com/scottckt/p/880670.html
Copyright © 2011-2022 走看看