Exemplo n.º 1
0
        private void btnNetWork_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("默认网卡地址:{0} \r\n", NetworkUtil.GetMacAddress2());
            sb.AppendFormat("本机IP:{0} \r\n", NetworkUtil.GetLocalIP());
            sb.AppendFormat("检测本机是否联网:{0} \r\n", NetworkUtil.IsConnectedInternet());
            sb.AppendFormat("www.iqid.com域名IP:{0} \r\n", NetworkUtil.ConvertDnsToIp("www.iqidi.com"));
            sb.AppendFormat("本机LocalHostName:{0}  \r\n", NetworkUtil.LocalHostName);
            sb.AppendFormat("本机局域网IP:{0}  \r\n", NetworkUtil.LANIP);
            sb.AppendFormat("本机广域网IP:{0}  \r\n", NetworkUtil.WANIP);

            sb.AppendLine();
            List <KeyValuePair <string, string> > netCardList = NetworkUtil.GetNetCardList();

            List <KeyValuePair <string, string> > .Enumerator enumNetCard = netCardList.GetEnumerator();
            List <string> macAddrs = new List <string>();

            while (enumNetCard.MoveNext())
            {
                KeyValuePair <string, string> p = enumNetCard.Current;
                string macAddr = NetworkUtil.GetPhysicalAddr(p.Key);
                if (macAddr != string.Empty)
                {
                    sb.AppendFormat("网卡[{0}]的真实地址:{1}", p.Value, macAddr);
                }
            }

            //Socket socket = NetworkUtil.CreateTcpSocket();
            //Socket udpsocket = NetworkUtil.CreateUdpSocket();
            //TcpListener listen = NetworkUtil.CreateTcpListener("127.0.0.1", 9900);
            //listen.Start(100);

            MessageDxUtil.ShowTips(sb.ToString());
        }