C++ 網絡抓包和操作庫:libtins

jopen 10年前發布 | 48K 次閱讀 libtins 網絡工具包

libtins 是一個高級支持多平臺的 C++ 網絡抓包和操作庫。開發者可以利用 libtins 在應用實現對網絡數據包的分析和操作。它的主要目的是提供C++開發??一個簡單,高效,平臺和字節序無關的方式來創建一個需要發送,接收和處理網絡數據包的工具。

它易于使用

該庫是非常簡單易用。作為一個簡單的例子,這是怎么回事,可以用來打印在eth0接口捕捉每一個TCP數據包的源地址和目的地址和端口:

#include <iostream>
#include <tins/tins.h>

using namespace Tins;

bool handler(const PDU &pdu) {
    const IP &ip = pdu.rfind_pdu<IP>(); // Find the IP layer
    const TCP &tcp = pdu.rfind_pdu<TCP>(); // Find the TCP layer
    std::cout << ip.src_addr() << ':' << tcp.sport() << " -> " 
              << ip.dst_addr() << ':' << tcp.dport() << std::endl;
    return true;
}

int main() {
    Sniffer("eth0").sniff_loop(handler);
}

特性

libtins 支持多種協議和特性:

  • Network packet crafting.
  • Packet sniffing and automatic interpretation packets.
  • Reading and writing PCAP files.
  • Following and reassembling TCP streams on the fly.
  • Decrypting WEP and WPA2(TKIP and CCMP) encrypted 802.11 data frames on the fly and interpreting the decrypted content.
  • Supported protocols:
    • IEEE 802.11
    • IEEE 802.3
    • IEEE 802.1q
    • Ethernet II
    • ARP
    • IP
    • IPv6
    • ICMP
    • ICMPv6
    • TCP
    • UDP
    • DHCP
    • DHCPv6
    • DNS
    • RadioTap
    • EAPOL
    • PPPoE
    • STP
    • LLC
    • LLC+SNAP
    • Linux Crooked Capture
    • PPI
    • NULL/Loopback

項目主頁:http://www.baiduhome.net/lib/view/home/1407554328317

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!