c#.net

c#.netcf network 연결상태

우유빛 2010. 8. 24. 16:39

public enum CradleResult : uint { cradled, uncradled, webException, otherException };

        const string Home = "127.0.0.1";

        public static void IsDeviceCradled()
        {
            try
            {
                string HostName = Dns.GetHostName();
                System.Net.IPHostEntry IPHost = Dns.GetHostByName(HostName);

                string DeviceIP = Convert.ToString( IPHost.AddressList[0] );
               
                if (DeviceIP != IPAddress.Parse(Home).ToString())
                {
                    MessageBox.Show(CradleResult.cradled.ToString());
                }
                else
                {
                    MessageBox.Show(CradleResult.uncradled.ToString());
                }
            }
            catch (System.Net.WebException webEx)
            {
                MessageBox.Show(CradleResult.webException.ToString());
            }
            catch (System.Exception othEx)
            {
                MessageBox.Show(CradleResult.otherException.ToString());
            }
        }