110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace rawsocket
{
class Program
{
static void Main(string[] args)
{
// const int SIO_RCVALL = unchecked((int)0x98000001);//监听所有的数据包
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);//creat a socket
socket.Blocking = false;
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
socket.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.111"),0)); //绑定套接字
//set
try
{
// socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
byte[] IN = new byte[4]{1,0,0,0};
byte[] OUT = new byte[4];
int ret_code = socket.IOControl(IOControlCode.ReceiveAll, IN, OUT);
Console.Write(Convert.ToString(ret_code)+"\r\n");
ret_code = OUT[0] + OUT[1] + OUT[2] + OUT[3];
Console.Write(Convert.ToString(ret_code)+"\r\n");
}
catch (SocketException e)
{
Console.Write(e.ToString()+"\r\n");
Console.Write(Convert.ToString(e.ErrorCode));
}
while (true)
{ }
}
}
}