public static string GetMyIP() { IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); string myip = string.Empty; foreach (IPAddress ia in host.AddressList) { if (ia.AddressFamily == AddressFamily.InterNetwork) { myip = ia.ToString();break; } } return myip; }private static string GetMacAddress(string ip) { string macAddress = null; System.Management.ObjectQuery query = new System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'"); System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query); foreach (System.Management.ManagementObject obj in searcher.Get()) { string[] ipAddress = (string[])obj["IPAddress"]; if (ipAddress[0] == ip && obj["MACAddress"] != null) { macAddress = obj["MACAddress"].ToString(); break; } } return macAddress; }
'.Net > Winform' 카테고리의 다른 글
C# MS Chart (2) | 2012.08.30 |
---|---|
C# ListView LargeIcon을 이용하여 Windows탐색기 효과내기 (2) | 2012.08.29 |
C# Ping 확인 (0) | 2012.08.28 |
C# 계정을 이용한 Directory Lock & Unlock (0) | 2012.08.28 |
C# ListView Headr Column Size 변경 막기 (0) | 2012.08.28 |