Namespace: System.Net 추가
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
}
아래는 MSDN
The following example uses the GetHostByName method to get the DNS information for the specified DNS host name.
try
{
IPHostEntry hostInfo = Dns.GetHostByName(hostName);
// Get the IP address list that resolves to the host names contained in the
// Alias property.
IPAddress[] address = hostInfo.AddressList;
// Get the alias names of the addresses in the IP address list.
String[] alias = hostInfo.Aliases;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nAliases : ");
for(int index=0; index < alias.Length; index++) {
Console.WriteLine(alias[index]);
}
Console.WriteLine("\nIP address list : ");
for(int index=0; index < address.Length; index++) {
Console.WriteLine(address[index]);
}
}
catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}'C#.NET' 카테고리의 다른 글
| [Microsoft Translator] Bing API를 이용한 초간단 번역기 만들기 (2) | 2010.05.13 |
|---|---|
| [BindingList 추가/삭제/수정 ] Update Insert Delete 한꺼번에 처리하기 (0) | 2010.04.08 |
| 엑셀출력시 0 사라짐 (0) | 2010.04.08 |
| enum 이름 가져오기 와 리소스(Resources)사용법 (0) | 2010.04.02 |
| [MSDN] EventHandler (0) | 2010.03.31 |
| [MSDN][BindingList] 데이터 바인드 개선 (0) | 2010.03.12 |
| [Binding] 컨트롤 바인딩 할떄 포멧변경 (0) | 2010.03.11 |
| Partial 클래스 (0) | 2010.03.10 |
| errorProvider을 이용한 에러체크하기 (0) | 2010.03.09 |
| openFileDialog로 텍스트파일 선택하기 (0) | 2010.03.06 |