ادرس ip کلاینت مورد نظر را میدین
//You'll need this pinvoke signature as it is not part of the .Net framework
[DllImport("iphlpapi.dll", ExactSpelling = true)]
public static extern int SendARP(int DestIP, int SrcIP,
byte[] pMacAddr, ref uint PhyAddrLen);
//These vars are needed, if the the request was a success
//the MAC address of the host is returned in macAddr
private byte[] macAddr = new byte[6];
private uint macAddrLen;
//Here you can put the IP that should be checked
private IPAddress Destination = IPAddress.Parse("127.0.0.1");
//Send Request and check if the host is there
if (SendARP((int)Destination.Address, 0, macAddr, ref macAddrLen) == 0)
{
//SUCCESS! Igor it's alive!
}
شما حتی می تونید کل ip های موجود در lan را بیابید و یکی یکی اونا رو پینگ کنید یا به صورت دستی از قبل موقع کانفیگ برنامه ادرس های ای پی را ست بکنی
برای بلاک کردن هم راه های زیادی هست . سریعترین روش اینه
Thread.CurrentThread.Suspend();
در مورد ارسال message هم دنبال مباحث
NetworkStream
socket programming
باشین
مثال برای ارسال اینگونه هست
public void SendMessage(TcpClient client, string message)
{
byte[] buffer = Encoding.ASCII.GetBytes(message);
NetworkStream stream = client.GetStream();
stream.Write(buffer, 0, buffer.Length);
client.Close();
}
برای دریافت هم تقریبا اینطوری میشه (کد های دقیق را خودت جستجو کن)
var stream = client.GetStream();
while (true)
{
byte[] buffer = new byte[2048];
int bytesRead = stream.Read(buffer, 0, 2048);
if (bytesRead > 0)
{
StringBuilder sb = new StringBuilder();
string v = Encoding.ASCII.GetString(buffer);
}
}