首页 > 编程语言 >C# 抓包工具

C# 抓包工具

时间:2023-04-14 22:44:41浏览次数:25  
标签:sourceIpData C# System buffer using new 工具 byte 抓包

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CatchTool
{
    class Program
    {
        private static Socket socket = null;
        static void Main(string[] args)
        {
            string localIP = "192.168.10.6";
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
            socket.Bind(new IPEndPoint(IPAddress.Parse(localIP), 0));
            socket.IOControl(IOControlCode.ReceiveAll, new byte[] { 1, 0, 0, 0 }, new byte[4]);
            Thread t = new Thread(Execute);
            t.IsBackground = true;
            t.Start();
            Console.WriteLine("start...");
            Console.ReadLine();
        }

        private static void Execute()
        {
            while (true)
            {
                try
                {
                    byte[] buffer = new byte[10240];
                    int count = socket.Receive(buffer);
                    if (count > 0)
                    {
                        int headerLen = (buffer[0] & 0xf) * 4;
                        if (buffer[9] == (int)ProtocolType.Tcp)
                        {
                            byte[] data = new byte[count - headerLen];
                            Array.Copy(buffer, headerLen, data, 0, data.Length);
                            byte[] sourceIpData = new byte[4];
                            Array.Copy(buffer, 12, sourceIpData, 0, 4);
                            byte[] destIpData = new byte[4];
                            Array.Copy(buffer, 16, destIpData, 0, 4);
                            string sourceIp = $"{sourceIpData[0]}.{sourceIpData[1]}.{sourceIpData[2]}.{sourceIpData[3]}";
                            string destIp = $"{destIpData[0]}.{destIpData[1]}.{destIpData[2]}.{destIpData[3]}";
                            Console.WriteLine($"source IP={sourceIp}    ,destination IP={destIp}");


                        }
                    }
                }
                catch (Exception)
                {

                    throw;
                }
            }
            


        }
    }
}

标签:sourceIpData,C#,System,buffer,using,new,工具,byte,抓包
From: https://www.cnblogs.com/zhangdezhang/p/17320171.html

相关文章

  • Dynamics 365 安装插件注册工具 PluginRegistration
    1.创建文件夹,例:D:\Dynamics_365_Development_Tools\pluginsTool2.powershell进入D:\Dynamics_365_Development_Tools\pluginsTool3.运行下面指令(直接复制粘贴到PowerShell即可),运行完成后按回车[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::T......
  • leetcode-1360-easy
    NumberofDaysBetweenTwoDatesWriteaprogramtocountthenumberofdaysbetweentwodates.Thetwodatesaregivenasstrings,theirformatisYYYY-MM-DDasshownintheexamples.Example1:Input:date1="2019-06-29",date2="201......
  • leetcode-844-easy
    BackspaceStringCompareGiventwostringssandt,returntrueiftheyareequalwhenbotharetypedintoemptytexteditors.'#'meansabackspacecharacter.Notethatafterbackspacinganemptytext,thetextwillcontinueempty.Example1:......
  • leetcode-830-easy
    PositionsofLargeGroupsInastringsoflowercaseletters,theselettersformconsecutivegroupsofthesamecharacter.Forexample,astringlikes="abbxxxxzyy"hasthegroups"a","bb","xxxx","z"......
  • leetcode-812-easy
    LargestTriangleAreaGivenanarrayofpointsontheX-Yplanepointswherepoints[i]=[xi,yi],returntheareaofthelargesttrianglethatcanbeformedbyanythreedifferentpoints.Answerswithin10-5oftheactualanswerwillbeaccepted.Exampl......
  • leetcode-944-easy
    DeleteColumnsToMakeSortedYouaregivenanarrayofnstringsstrs,allofthesamelength.Thestringscanbearrangedsuchthatthereisoneoneachline,makingagrid.Forexample,strs=["abc","bce","cae"]canb......
  • Ubuntu20.04 Docker搭建远程xfce桌面以及ssh教程
    简介:本文主要介绍ubuntu20.04容器中搭建xfce远程桌面、C++、Go环境、容器内docker操作配置、zsh配置  一、创建容器1、创建容器dockerpull ubuntu:20.04dockerrun-itd--privileged--name=my-desktop--ulimitmemlock=-1:-1--network="network-local"-p22666:22-p......
  • 导入 Microsoft Dynamics 365 解决方案时发生 LocalizedNames 错误,元素 savedquery 的
    尝试在Dynamics365中导入解决方案时,会收到以下错误:“无法导入此解决方案包,因为它包含无效的XML。可以尝试使用架构验证错误中找到的信息手动编辑XML内容来修复文件,也可以联系解决方案提供商。错误代码8004801a。如果选择“技术详细信息”,则会看到以下消息以及其他......
  • CppDepend2023.1分析
        这是一个.Net程序,使用dotfuscator进行了混淆。虽然混淆了,但是不影响调试,可以直接使用dnspy进行调试。Help>LicenseInformation可以作为调试的入口点。    通过实时调试可以很轻松的找到校验授权的代码,在CppDepend.Core.dll中。可以将其修改为总是返回true。......
  • SpringSecurity过滤器-CsrfFilter
    CsrfFilter是为了防御CSRF攻击的。CSRF攻击请参考松哥手把手教你在SpringBoot中防御CSRF攻击!soeasy!。CsrfFilter的源码在要学就学透彻!SpringSecurity中CSRF防御源码解析说的很清楚了。 在这里是对LazyCsrfTokenRepository的使用做个总结。 CsrfFilter#doFilterI......