C# C中的Http监视器
这是我监视Http的代码:C# C中的Http监视器,c#,http,sockets,proxy,C#,Http,Sockets,Proxy,这是我监视Http的代码: static void Main(string[] args) { try { byte[] input = BitConverter.GetBytes(1); byte[] buffer = new byte[4096]; Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
static void Main(string[] args)
{
try
{
byte[] input = BitConverter.GetBytes(1);
byte[] buffer = new byte[4096];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
s.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80));
s.IOControl(IOControlCode.ReceiveAll, input, null);
s.BeginReceive(arrResponseBytes, 0, arrResponseBytes.Length, SocketFlags.None, new AsyncCallback(OnClientReceive), s);
System.Threading.ManualResetEvent reset = new System.Threading.ManualResetEvent(false);
reset.WaitOne();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadKey();
}
static byte[] arrResponseBytes = new byte[1024 * 5];
protected static void OnClientReceive(IAsyncResult ar)
{
Socket socket = (Socket)ar.AsyncState;
int count = socket.EndReceive(ar);
if (count > 0)
{
Console.WriteLine(Encoding.ASCII.GetString(arrResponseBytes, 0, count));
socket.BeginReceive(arrResponseBytes, 0, arrResponseBytes.Length, SocketFlags.None, new AsyncCallback(OnClientReceive), socket);
}
}
但我无法获得http主机。
我不知道是什么数据。
我想获得http主机,例如:
如何监视系统http?
谢谢。您在链接中看到的是。您应该解析IP和TCP头以提取内容。TCP内容大约从偏移量40开始。因此,您可以尝试您的程序的修改版本,如下所示,以查看每个HTTP请求的内容。只是为了给你一个想法而工作,而不是完成程序 PS:见s.BindNewIPendPointIPAddress.Broadcast,80;
这是我的数据:你试过解压吗?有可能在服务器端进行压缩,这是由一个头通知的,然后您只会看到垃圾。无论如何,我不确定你是否能区分不同的请求,但正如我所说的,我不确定这是否会成为一个问题。你如何使用fiddler软件?我想获得浏览器的重新测试。我正在使用-我倾向于不重新发明轮子,只要其他人可能知道更多,或者我完全错过了一个功能。顺便说一句:Fiddler的工作是:“HTTPS是一个更难的事情:你需要伪造一个证书类型的中间人,这将照亮典型的警告,在浏览器上试图创建一个新的控制台应用程序使用这个代码,什么也没有发生。
static void Main(string[] args)
{
try
{
byte[] input = new byte[]{1};
byte[] buffer = new byte[4096];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
s.Bind(new IPEndPoint(IPAddress.Broadcast, 80));
s.IOControl(IOControlCode.ReceiveAll , input, null);
s.BeginReceive(arrResponseBytes, 0, arrResponseBytes.Length, SocketFlags.None, new AsyncCallback(OnClientReceive), s);
System.Threading.ManualResetEvent reset = new System.Threading.ManualResetEvent(false);
reset.WaitOne();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadKey();
}
static byte[] arrResponseBytes = new byte[1024 * 64];
static void OnClientReceive(IAsyncResult ar)
{
Socket socket = (Socket)ar.AsyncState;
int count = socket.EndReceive(ar);
if (count >= 40)
{
try
{
string s = Encoding.UTF8.GetString(arrResponseBytes, 40, count - 40);
string bin = BitConverter.ToString(arrResponseBytes, 40, count - 40).Replace("-", " ");
if(s.StartsWith("GET"))
Console.WriteLine(s + " - " + bin);
//Thread.Sleep(1000);
}
catch { }
}
socket.BeginReceive(arrResponseBytes, 0, arrResponseBytes.Length, SocketFlags.None, new AsyncCallback(OnClientReceive), socket);
}