zoukankan      html  css  js  c++  java
  • 通过网卡获取http请求数据

    这个代码的原始地址是:http://www.codeproject.com/KB/cpp/sniffer80.aspx

    这个是朋友反编译了一下,同时对http的解包再做了一些修改后的代码,我拿来用了。

    代码调用也很简单

     1 using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Data;
    5 using System.Drawing;
    6 using System.Text;
    7 using System.Windows.Forms;
    8 using System.Net;
    9 using Sniffer;
    10
    11 namespace snifferHttp
    12 {
    13 public partial class Form1 : Form
    14 {
    15 public Form1()
    16 {
    17 InitializeComponent();
    18 }
    19
    20 private static SnifferSocket m_Sniffer;
    21 private void Form1_Load(object sender, EventArgs e)
    22 {
    23 m_Sniffer = new SnifferSocket();
    24 m_Sniffer.TcpPacketReceived += new TcpPacketCallback(m_Sniffer_TcpPacketReceived);
    25 IPAddress[] addressList = Dns.GetHostAddresses(Dns.GetHostName());
    26
    27 if (addressList.Length != 0)
    28 {
    29 foreach (IPAddress ip in addressList)
    30 {
    31 if (ip.ToString().Split('.').Length == 4) m_Sniffer.Sniff(ip.ToString());
    32 }
    33 }
    34 }
    35
    36 void m_Sniffer_TcpPacketReceived(TcpPacket packet)
    37 {
    38 string data = Encoding.ASCII.GetString(packet.Data);
    39 if (data.StartsWith("GET "))
    40 {
    41 HttpSniffer.HttpPacket sn = new HttpSniffer.HttpPacket();
    42 sn.ParseRequest(data);
    43
    44 this.SetText("Get Request host:" + sn.Host + ",url:" + sn.URL+"cookie:"+sn.Cookie);
    45 }
    46 else if (data.StartsWith("HTTP/"))
    47 {
    48 HttpSniffer.HttpPacket sn = new HttpSniffer.HttpPacket();
    49 sn.ParseRequest(data);
    50 this.SetText("Get Response host:" + sn.Host + ",url:" + sn.URL + "cookie:" + sn.Cookie);
    51 }
    52 }
    53
    54 private void SetText(string text)
    55 {
    56 try
    57 {
    58 this.Invoke((EventHandler)delegate
    59 {
    60 this.textBox1.AppendText(text + "\r\n");
    61 });
    62 }
    63 catch { }
    64 }
    65 }
    66 }


    源代码下载:https://files.cnblogs.com/rq204/SnifferHttp.7z

  • 相关阅读:
    ligerui做分页显示数据
    js判断input为空校验
    js操作table倒叙显示序号的问题
    js获取div中的文本框数据
    js数组到后台转 list数组
    table 操作
    js操作table
    父页面调用子页面的方法
    laravel修改密码及与原密码Hash::check比较 阿星小栈
    php获取中文字符拼音首字母 阿星小栈
  • 原文地址:https://www.cnblogs.com/rq204/p/2310905.html
Copyright © 2011-2022 走看看