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

GetHostName 및 GetHostByName

C#/Network 2012. 6. 13. 15:10 Posted by 퓨어레드
// 호스팅 이름을 리턴한다.
string hostName = Dns.GetHostName ();

string result = string.Format ("Local hostname : {0}\r\n", hostName);

// IP 엔트리를 리턴한다.
IPHostEntry myself = Dns.GetHostByName (hostName);

foreach (IPAddress ip in myself.AddressList)

	 result += string.Format ("IP Address : {0}\r\n", ip.ToString ());


txtIpInfo.Text = result;

 

============== 결과 ================
Local hostname : red
 
IP Address : 192.168.219.12

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

IPAddress  (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

C# POSTDATA 파일 업로드

C#/Network 2012. 6. 4. 18:20 Posted by 퓨어레드

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

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

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

GetHostName 및 GetHostByName  (0) 2012.06.13
C# POSTDATA 파일 업로드  (0) 2012.06.04
Socket Server 연결 Sample  (0) 2012.04.18
Socket Client 연결 Sample  (0) 2012.04.18
네트워크 바이트 오더 변경 클래스  (0) 2012.04.17

Socket Server 연결 Sample

C#/Network 2012. 4. 18. 10:18 Posted by 퓨어레드

서버 바인딩 후 Accept 샘플

 

IPEndPoint serverBindInf = new IPEndPoint (IPAddress.Any, 9999);

Socket serverSocket = new Socket (AddressFamily.InterNetwork, 
	SocketType.Stream, ProtocolType.Tcp);
  
// ServerSocket Bind..
serverSocket.Bind (serverBindInf);

// Listen..
serverSocket.Listen (10);
 
// Client Accept!
Socket clientSocket = serverSocket.Accept ();
 
// Socket 종료
clientSocket.Close ();
 
serverSocket.Close ();

 

Socket Client 연결 Sample

C#/Network 2012. 4. 18. 10:15 Posted by 퓨어레드

Socket 을 써서 연결하는 샘플

 

IPEndPoint serverEndPoint = new IPEndPoint (IPAddress.Parse ("127.0.0.1"), 9999);

// Client 용 소켓 생성
Socket serverSocket = new Socket (AddressFamily.InterNetwork, 
SocketType.Stream, ProtocolType.Tcp);

// 서버 연결!
try
{
    serverSocket.Connect (serverEndPoint);
}
catch (SocketException ex)
{
    Console.WriteLine ("Unable to connect to server.");
    Console.WriteLine (ex.ToString ());
 
    return;
}

serverSocket.Shutdown (SocketShutdown.Both);
serverSocket.Close ();

 

 

네트워크 바이트 오더 변경 클래스

C#/Network 2012. 4. 17. 18:06 Posted by 퓨어레드

로컬 바이트 오더를 네트워크 바이트 오더로 변경한다.

short sData = 10;

// 네트워트 바이트 오더로 변경
short sDataB = IPAddress.HostToNetworkOrder (sData);

byte [] networkBytes = BitConverter.GetBytes (sDataB);

 

네트워크 바이트 오더를 로컬 바이트 오더로 변경한다.

 

short sDataB = BitConverter.ToInt16 (networkBytes);

// 네트워크 바이트 오더를 로컬 바이트 오더로 변경

short sData = IPAddress.NetworkToHostOrder (sDataB);

 

 

'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