반응형
public static class SystemClass
{
// 하드시리얼넘버
public static string GetHDDSerialNumber(string drive)
{
if (drive == "" || drive == null)
{
drive = "C";
}
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
disk.Get();
return disk["VolumeSerialNumber"].ToString();
}
// 외부 아이피
public static string GetIP()
{
string tempIp = string.Empty;
try
{
tempIp = new WebClient().DownloadString("http://www.whatismyip.com/automation/n09230945.asp");
}
catch (WebException)
{
try
{
tempIp = GetExternalIp().ToString();
}
catch (Exception)
{
MessageBox.Show("아이피를 찾지 못했습니다");
}
}
return tempIp;
}
public static IPAddress GetExternalIp()
{
string checkip = "http://checkip.dyndns.org/";
WebClient wc = new WebClient();
UTF8Encoding utf8 = new UTF8Encoding();
string requestHtml = "";
try
{
requestHtml = utf8.GetString(wc.DownloadData(checkip));
requestHtml = requestHtml.Substring(75).Remove(requestHtml.Substring(75).IndexOf("</body>")).Trim();
}
catch (WebException we)
{
// do something with exception
Console.Write(we.ToString());
}
IPAddress externalIp = IPAddress.Parse(requestHtml);
return externalIp;
}
// DNS
public static string GetDNS()
{
return System.Net.Dns.GetHostByName("LocalHost").HostName;
}
//NetBios
public static string GetNetBios()
{
return System.Environment.MachineName;
}
// 내부 아이피
public static string GetInnerIp()
{
IPAddress ipaddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
return ipaddress.ToString();
}
// 내부 아이피 전부
public static List<string> GetInnerIpAll()
{
IPHostEntry hostEntry = Dns.GetHostByName(Dns.GetHostName());
List<string> list = new List<string>();
for (int i = 0; i < hostEntry.AddressList.Length; i++)
{
list.Add(hostEntry.AddressList[i].ToString());
}
return list;
}
// 그위드
public static string GetGUID()
{
Guid guid = Guid.NewGuid();
return guid.ToString().ToUpper();
}
// 클릭온스버전
public static string GetSmartVersion()
{
if (ApplicationDeployment.IsNetworkDeployed)
{
Version myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
return string.Format("{0}.{1}.{2}.{3} Build", myVersion.Major, myVersion.Minor, myVersion.Build, myVersion.Revision);
}
else return string.Empty;
}
}
}
'.NET > C# Basic' 카테고리의 다른 글
[C#] String.Format 을 이용한 문자정렬 왼쪽 오른쪽 가운데 | String alignment Left Right Center (0) | 2010.03.20 |
---|---|
[C#] char[] + char[] = char[]?? | char[] Merge (0) | 2010.02.09 |
[C#] Thread를 정복해 보자 (0) | 2010.02.06 |
사용예) StringCollection 과 string[] int[] converterMethod (0) | 2010.02.02 |
C# 프로그래밍 도구 (0) | 2009.12.02 |
내가 좋아하는 SortedList (0) | 2009.08.14 |
Array.Find / List.Find Method 사용 예 (0) | 2009.08.07 |
.net 설치 배포 방법 (0) | 2009.07.28 |