C#做的配套C做的SNIFFER(C#)--C#简单而实用

来源:互联网 发布:linux ntp时间服务器 编辑:程序博客网 时间:2024/04/30 05:52
 

//C#实现系统界面
//本模块完成几个程序的连接
//并实现文件扫描后数据库的信息导入,
//通过对伪IP数据包标识符&65280(获取高八位)查询数据库相关记录获取IP
//按照visual studio C#windows窗体设计步骤

 

//Program.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
namespace WMF_WIP系统
{
   
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
   public  class IPscanDYc
    {    
       public static void track()
        {
          // 实例一个Process类,启动一个独立进程
         Process p1 = new Process();
         p1.StartInfo.FileName = "Telnet.exe";
         p1.StartInfo.CreateNoWindow =false;
         p1.Start();

        }
       public static void capture()
       {
           Process p2 = new Process();
           p2.StartInfo.FileName ="iptool\\IpTool.exe";
           p2.StartInfo.CreateNoWindow = false;
           p2.Start();

       }
       public static void BUG()
       {
           Process p3 = new Process();
           p3.StartInfo.FileName = "FTP\\xlight.exe";
           p3.StartInfo.CreateNoWindow = false;
           p3.Start();
       }
       public static void help(string s)
       {
           Process p4 = new Process();
           p4.StartInfo.FileName = s;
           p4.StartInfo.CreateNoWindow = false;
           p4.Start();
       }

     }
   public class DBQ
   {
       static string ID = Application.StartupPath;
       public static void _TxtInDB(TextBox info)
       {
           char fenge= '#';//按照#分割
           StreamReader sr = new StreamReader(new FileStream("log.txt", FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);
           SqlConnection cn = new SqlConnection("Server=.;uid=wmf;pwd=wmf;database=WIP"); ;
           string insertCmd = "insert into WIP values (@ID, @SIP, @Content)";
           string[] WMF = null;//得到的一行的数据()
           string strTemp = sr.ReadLine();
           while(strTemp != null)
           {
               WMF = strTemp.Split(fenge);
               SqlCommand cmd = new SqlCommand(insertCmd, cn);
               cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = WMF[0];
               cmd.Parameters.Add("@SIP", SqlDbType.VarChar).Value = WMF[1];
               cmd.Parameters.Add("@Content", SqlDbType.VarChar).Value = WMF[2];
               cn.Open();
               try
               {
                   cmd.ExecuteNonQuery();
               }
               catch (System.Data.SqlClient.SqlException e)
               {
                   info.Text = "错误";
               }
               cn.Close();
               strTemp = sr.ReadLine();
           }
           sr.Close();
       }


       public static void _SDB(TextBox T3,TextBox T5, string p)
       {
           //创建数据库连接
           int i=0,n=0;   
           if(T3.Text.Length==0) i=0; 
           else i=Convert.ToInt32(p)&65280;
           T3.AppendText(i.ToString());
           SqlConnection objSqlConnection=new SqlConnection("server=.;uid=wmf;pwd=wmf;database=WIP"); 
           objSqlConnection.Open();
           T5.Text = "连接成功"; 
           string query="SELECT * from WIP where PacketID&65280="+i;
           SqlCommand objSqlCommand=new SqlCommand(query,objSqlConnection);
           SqlDataReader objSqlReader=objSqlCommand.ExecuteReader();
           while(objSqlReader.Read()) 
           {  n+=1;
           T3.Text= objSqlReader.GetValue(1).ToString();
           T5.Text=objSqlReader.GetValue(2).ToString();
           }
           if(n==0)  T5.AppendText("数据库中没有这样的记录!");
       }

   }

}

 

//from1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WMF_WIP系统
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //调用本地抓包软件
        private void button2_Click(object sender, EventArgs e)
        {
            IPscanDYc.capture();
        }
                //实用特殊登录
        private void button1_Click(object sender, EventArgs e)
        {
            IPscanDYc.track();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            IPscanDYc.BUG();
        }

        private void button4_Click(object sender, EventArgs e)
        {
          
            DBQ._TxtInDB(textBox5);//信息入库
            DBQ._SDB(textBox3, textBox5, textBox1.Text);//对数据包数据库分析
        }

     
    
    }
}
//form1.designer.cs
namespace WMF_WIP系统
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码
        /// 设计器支持所需的方法 - 不要轻易
        /// 使用代码编辑器修改此方法的内容。
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            this.textBox4 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.工具ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.选项ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.测试ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.分析ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.数据分析ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.panel2 = new System.Windows.Forms.Panel();
            this.textBox5 = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.button4 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.教程ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.说明ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.帮助ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.panel1.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.panel2.SuspendLayout();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.button1.Location = new System.Drawing.Point(108, 54);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(86, 39);
            this.button1.TabIndex = 0;
            this.button1.Text = "远程登录";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // panel1
            //
            this.panel1.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.panel1.Controls.Add(this.textBox4);
            this.panel1.Controls.Add(this.textBox3);
            this.panel1.Controls.Add(this.textBox2);
            this.panel1.Controls.Add(this.textBox1);
            this.panel1.Controls.Add(this.label4);
            this.panel1.Controls.Add(this.label3);
            this.panel1.Controls.Add(this.label2);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Location = new System.Drawing.Point(0, 99);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(367, 247);
            this.panel1.TabIndex = 3;
            //
            // textBox4
            //
            this.textBox4.Location = new System.Drawing.Point(22, 197);
            this.textBox4.Multiline = true;
            this.textBox4.Name = "textBox4";
            this.textBox4.Size = new System.Drawing.Size(144, 21);
            this.textBox4.TabIndex = 7;
            //
            // textBox3
            //
            this.textBox3.Location = new System.Drawing.Point(22, 146);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(144, 21);
            this.textBox3.TabIndex = 6;
            //
            // textBox2
            //
            this.textBox2.Location = new System.Drawing.Point(22, 97);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(144, 21);
            this.textBox2.TabIndex = 5;
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(22, 44);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(144, 21);
            this.textBox1.TabIndex = 4;
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label4.Location = new System.Drawing.Point(18, 174);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(78, 20);
            this.label4.TabIndex = 3;
            this.label4.Text = "真实IP行为";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label3.Location = new System.Drawing.Point(18, 122);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(50, 20);
            this.label3.TabIndex = 2;
            this.label3.Text = "真实IP";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label2.Location = new System.Drawing.Point(18, 74);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(36, 20);
            this.label2.TabIndex = 1;
            this.label2.Text = "伪IP";
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label1.Location = new System.Drawing.Point(18, 20);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(148, 20);
            this.label1.TabIndex = 0;
            this.label1.Text = "伪IP数据包的标识字段";
            //
            // menuStrip1
            //
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.文件ToolStripMenuItem,
            this.工具ToolStripMenuItem,
            this.选项ToolStripMenuItem,
            this.测试ToolStripMenuItem,
            this.分析ToolStripMenuItem,
            this.数据分析ToolStripMenuItem,
            this.教程ToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(795, 25);
            this.menuStrip1.TabIndex = 6;
            this.menuStrip1.Text = "menuStrip1";
            //
            // 文件ToolStripMenuItem
            //
            this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem";
            this.文件ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
            this.文件ToolStripMenuItem.Text = "文件";
            //
            // 工具ToolStripMenuItem
            //
            this.工具ToolStripMenuItem.Name = "工具ToolStripMenuItem";
            this.工具ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
            this.工具ToolStripMenuItem.Text = "工具";
            //
            // 选项ToolStripMenuItem
            //
            this.选项ToolStripMenuItem.Name = "选项ToolStripMenuItem";
            this.选项ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
            this.选项ToolStripMenuItem.Text = "选项";
            //
            // 测试ToolStripMenuItem
            //
            this.测试ToolStripMenuItem.Name = "测试ToolStripMenuItem";
            this.测试ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
            this.测试ToolStripMenuItem.Text = "测试";
            //
            // 分析ToolStripMenuItem
            //
            this.分析ToolStripMenuItem.Name = "分析ToolStripMenuItem";
            this.分析ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
            this.分析ToolStripMenuItem.Text = "分析";
            //
            // 数据分析ToolStripMenuItem
            //
            this.数据分析ToolStripMenuItem.Name = "数据分析ToolStripMenuItem";
            this.数据分析ToolStripMenuItem.Size = new System.Drawing.Size(68, 21);
            this.数据分析ToolStripMenuItem.Text = "数据分析";
            //
            // panel2
            //
            this.panel2.BackColor = System.Drawing.Color.CornflowerBlue;
            this.panel2.Controls.Add(this.textBox5);
            this.panel2.Controls.Add(this.label6);
            this.panel2.Location = new System.Drawing.Point(394, 28);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(402, 333);
            this.panel2.TabIndex = 9;
            //
            // textBox5
            //
            this.textBox5.Location = new System.Drawing.Point(9, 36);
            this.textBox5.Multiline = true;
            this.textBox5.Name = "textBox5";
            this.textBox5.Size = new System.Drawing.Size(417, 266);
            this.textBox5.TabIndex = 5;
            //
            // label6
            //
            this.label6.AutoSize = true;
            this.label6.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label6.Location = new System.Drawing.Point(4, 4);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(88, 16);
            this.label6.TabIndex = 0;
            this.label6.Text = "数据包信息";
            //
            // button4
            //
            this.button4.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.button4.Location = new System.Drawing.Point(281, 54);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(86, 39);
            this.button4.TabIndex = 12;
            this.button4.Text = "信源追踪";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            //
            // button2
            //
            this.button2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.button2.Location = new System.Drawing.Point(0, 54);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(102, 39);
            this.button2.TabIndex = 13;
            this.button2.Text = "数据包捕获";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // button5
            //
            this.button5.Font = new System.Drawing.Font("幼圆", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.button5.Location = new System.Drawing.Point(200, 54);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(75, 39);
            this.button5.TabIndex = 14;
            this.button5.Text = "文件传输";
            this.button5.UseVisualStyleBackColor = true;
            this.button5.Click += new System.EventHandler(this.button5_Click);
            //
            // 教程ToolStripMenuItem
            //
            this.教程ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.说明ToolStripMenuItem,
            this.帮助ToolStripMenuItem});
            this.教程ToolStripMenuItem.Name = "教程ToolStripMenuItem";
            this.教程ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
            this.教程ToolStripMenuItem.Text = "教程";
            //
            // 说明ToolStripMenuItem
            //
            this.说明ToolStripMenuItem.Name = "说明ToolStripMenuItem";
            this.说明ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.说明ToolStripMenuItem.Text = "说明";
            this.说明ToolStripMenuItem.Click += new System.EventHandler(this.说明ToolStripMenuItem_Click);
            //
            // 帮助ToolStripMenuItem
            //
            this.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem";
            this.帮助ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.帮助ToolStripMenuItem.Text = "帮助";
            this.帮助ToolStripMenuItem.Click += new System.EventHandler(this.帮助ToolStripMenuItem_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(795, 370);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "伪IP地址数据包追踪程序";
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.panel2.ResumeLayout(false);
            this.panel2.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label2;
        public System.Windows.Forms.TextBox textBox4;
        public System.Windows.Forms.TextBox textBox3;
        public System.Windows.Forms.TextBox textBox2;
        public System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 工具ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 选项ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 测试ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 分析ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 数据分析ToolStripMenuItem;
        private System.Windows.Forms.Panel panel2;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.TextBox textBox5;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button5;
        private System.Windows.Forms.ToolStripMenuItem 教程ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 说明ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 帮助ToolStripMenuItem;
    }
}

原创粉丝点击