• 大小: 120KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-11
  • 语言: C#
  • 标签: rawsocket  

资源简介

C#写的原始套接字数据包转发代码,可以检测到传入和发出的所有端口的数据包。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting.Contexts;
using System.IO;
using Microsoft.VisualBasic;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        RawSocket raw;
        FileStream f;
        public Form1()
        {
            InitializeComponent();
            f = new FileStream(@“c:\gps_sdp.log“ FileMode.OpenOrCreate);
        }

        
        private void PackageAccept(object sender PacketArrivedEventArgs args)
        {
            RawSocket.PacketArrivedEventHandler d = new RawSocket.PacketArrivedEventHandler(PackageAccept2);
            this.Invoke(d new object[] { sender args });
        }
        private void PackageAccept2(object sender PacketArrivedEventArgs args)
        {
            if (!((args.DestinationAddress == txtDestIP.Text && args.OriginationAddress == txtOriginIP.Text)))//||
                //(args.DestinationAddress == txtLocalIP.Text && args.OriginationAddress == txtRemoveIP.Text)))
                return;
            string s = “\r\n“ + args.OriginationAddress + ‘:‘ + args.OriginationPort + “-->“ +
                args.DestinationAddress + ‘:‘ + args.DestinationPort + “  “ + args.MessageBuffer.Length.ToString();
            string data=““;
            //for (int i = 0; i < Math.Min(args.MessageBuffer.Length args.MessageLength); i++)
            //{
            //    data += Conversion.Hex(args.MessageBuffer[i]);
            //}

            s += Encoding.ASCII.GetString(args.MessageBuffer 0 (int)args.MessageLength);
            s  = s.Replace(‘\0‘ ‘0‘);
            textBox1.AppendText(s +“  “ + data);
            Application.DoEvents();
            //args.MessageBuffer//
        }

        private void button1_Click(object sender EventArgs e)
        {
            raw = new RawSocket();
            raw.CreateAndBindSocket(txtOriginIP.Text);
            raw.OnPacketArrival += new RawSocket.PacketArrivedEventHandler(PackageAccept);
            updateRowSocket();
            raw.Run();
        }

        private void button2_Click(object sender EventArgs e)
        {
            raw.Shutdown();
        }

        private void updateControl()
        {
            groupBox1.Enabled = chkMapPort.Checked;
            
        }

        private void updateRowSocket()
        {
            if(raw != null && chkMapPort.Checked)
            {
                raw.SetRemoteIP(txtDestIP.Text);
                raw.PackageInFromTo(short.Parse(txtInFromPort.Text) short.Parse(txtInToPort.Text));
                raw.PackageOutFromTo(short.Parse(txtOutFromPort.Text) short.Parse(txtOutToPort.Text));
                raw.MapPort = chkMapPort.Checked;
            }
        }

        private void chkMapPort_CheckedChanged(object sender EventArgs e)
        {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3348  2012-05-13 16:10  _UpgradeReport_Files\UpgradeReport.css

     文件      12505  2008-01-11 01:25  _UpgradeReport_Files\UpgradeReport.xslt

     文件         69  2012-05-13 16:10  _UpgradeReport_Files\UpgradeReport_Minus.gif

     文件         71  2012-05-13 16:10  _UpgradeReport_Files\UpgradeReport_Plus.gif

     文件       2647  2009-09-14 12:03  Backup\Form1.cs

     文件      12441  2009-09-14 12:03  Backup\Form1.Designer.cs

     文件       5814  2009-09-14 12:03  Backup\Form1.resx

     文件        478  2007-03-10 10:30  Backup\Program.cs

     文件       1204  2007-03-10 10:30  Backup\Properties\AssemblyInfo.cs

     文件       2836  2007-03-13 14:49  Backup\Properties\Resources.Designer.cs

     文件       5612  2007-03-10 10:30  Backup\Properties\Resources.resx

     文件       1103  2007-03-13 14:49  Backup\Properties\Settings.Designer.cs

     文件        249  2007-03-10 10:30  Backup\Properties\Settings.settings

     文件      20282  2007-03-18 14:03  Backup\RawClass.cs

     文件       3446  2009-09-14 11:56  Backup\数据包转发.csproj

     文件        918  2007-03-13 14:47  Backup\数据包转发.sln

    ..A..H.     23552  2009-09-14 12:11  Backup\数据包转发.suo

     文件      20480  2012-09-05 23:42  bin\Debug\数据包转发.exe

     文件      44544  2012-09-05 23:42  bin\Debug\数据包转发.pdb

     文件      14328  2012-09-06 00:09  bin\Debug\数据包转发.vshost.exe

     文件        490  2009-06-11 05:14  bin\Debug\数据包转发.vshost.exe.manifest

     文件        180  2012-09-05 23:25  obj\Debug\RAWTest.Properties.Resources.resources

     文件       4608  2012-05-13 16:11  obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        842  2007-03-11 17:42  obj\Debug\WindowsApplication1.csproj.GenerateResource.Cache

     文件        180  2012-09-05 23:42  obj\Debug\WindowsApplication1.Form1.resources

     文件       1480  2012-09-06 00:09  obj\Debug\数据包转发.csproj.FileListAbsolute.txt

     文件        847  2012-09-05 23:42  obj\Debug\数据包转发.csproj.GenerateResource.Cache

     文件      20480  2012-09-05 23:42  obj\Debug\数据包转发.exe

     文件      44544  2012-09-05 23:42  obj\Debug\数据包转发.pdb

     文件        842  2007-03-11 13:44  obj\Release\WindowsApplication1.csproj.GenerateResource.Cache

............此处省略41个文件信息

评论

共有 条评论