IPAddress

C#/Network 2012. 6. 13. 15:14 Posted by 퓨어레드
/************************************************************************/
/* IPAddress : 하나의 주소를 표현함
/************************************************************************/

IPAddress test1 = IPAddress.Parse("192.168.1.1");
IPAddress test2 = IPAddress.Loopback;
IPAddress test3 = IPAddress.Broadcast;
IPAddress test4 = IPAddress.Any;
IPAddress test5 = IPAddress.None;

IPHostEntry ihe = Dns.GetHostByName (Dns.GetHostName ());

IPAddress myself = ihe.AddressList[0];

if (IPAddress.IsLoopback (test2))
{
	result += String.Format ("The Loopback address is : {0}\r\n", test2.ToString ());
}
else
	result += "Error obtaining the loopback address\r\n";

result += String.Format ("The Local IP address is {0}\r\n", myself.ToString ());

if (myself == test2)
	result += "The loopback address is the same as local address.\r\n";
else
	result += "The loopback address is not the local address.\r\n";

result += String.Format ("The test address is : {0}\r\n", test1.ToString ());
result += String.Format ("Boardcast address is : {0}\r\n", test3.ToString ());
result += String.Format ("Any address is : {0}\r\n", test4.ToString ());
result += String.Format ("The NONE address is : {0}\r\n", test5.ToString ());

 

결과 ...

====================================

 

The Loopback address is : 127.0.0.1
The Local IP address is 192.168.123.176
The loopback address is not the local address.
The test address is : 192.168.1.1
Boardcast address is : 255.255.255.255
Any address is : 0.0.0.0
The NONE address is : 255.255.255.255

'C# > Network' 카테고리의 다른 글

GetHostName 및 GetHostByName  (0) 2012.06.13
C# POSTDATA 파일 업로드  (0) 2012.06.04
C# HttpWebRequest 클래스를 이용한 POST 전송하기  (0) 2012.06.04
Socket Server 연결 Sample  (0) 2012.04.18
Socket Client 연결 Sample  (0) 2012.04.18