using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
public bool PingConnect(string ip, int port)
{
bool connect = false;
try
{
//IP Address 할당
IPAddress ipAddress = IPAddress.Parse(ip);
//TCP Client 선언
TcpClient tcpClient = new TcpClient(AddressFamily.InterNetwork);
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
// Ping 성공시
connect = true;
}
else
{
// Ping 실패시 강제 Exception
throw new Exception();
}
return connect;
}
catch (Exception ex)
{
return false;
}
}
Build Cross-Platform Mobile Apps using C# and .NET (0) | 2012.03.16 |
---|---|
http://kongmks.blog.me/10012352792 (0) | 2012.03.10 |
C# Application 하나만 실행되게. (0) | 2012.03.06 |
문자열 수식 계산기 (0) | 2012.03.02 |
Sample Entity Framework Provider For Oracle (0) | 2012.02.29 |