⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 packetdns.cs

📁 一个抓包工具
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Windows.Forms;

namespace MyClasses
{

	public class PacketDNS
	{

		/*public struct PACKET_DNS_QUERY
		{
			public string Name;
			public ushort Type;
			public string TypeStr;
			public ushort Class;
			public string ClassStr;
		}*/

		public struct QUESTION_ITEM
		{
			public string Name;
			public ushort Type;
			public string TypeStr;
			public ushort Class;
			public string ClassStr;
		}

		public struct ANSWER_ITEM
		{
			public string Name;
			public string NameStr;
			public ushort Type;
			public string TypeStr;
			public ushort Class;
			public string ClassStr;
			public uint TimeToLive;
			public ushort DataLength;
			public string IpAddress;
		}

		/*public struct ANSWER_ITEM
		{
			public string Name;
			public ushort Type;
			public string TypeStr;
			public ushort Class;
			public string ClassStr;
			public uint TimeToLive;
			public string TimeToLiveStr;
			public ushort DataLength;
			public ushort Flags;
			public string FlagsStr;
			public uint Address;
			public string AddressStr;
		}*/

		public struct AUTHORITY_ITEM
		{
			public string Name;
			public ushort Type;
			public string TypeStr;
			public ushort Class;
			public string ClassStr;
			public uint TimeToLive;
			public ushort DataLength;
			public string PrimaryNameServer;
			public string ResponsibleAuthoritysMailBox;
			public uint SerialNumber;
			public uint RefreshInterval;
			public uint RetryInterval;
			public uint ExpirationLimit;
			public uint MinimumTTL;
		}


		public struct ADDITIONAL_ITEM
		{
			public string Name;
			public ushort Type;
			public string TypeStr;
			public ushort Class;
			public string ClassStr;
			public uint TimeToLive;
			public string TimeToLiveStr;
			public ushort DataLength;
			public ushort Flags;
			public string FlagsStr;
			public uint Address;
			public string AddressStr;
		}



		public struct PACKET_DNS
		{
			public ushort TransactionId;
			public ushort Flags;
			public string FlagsStr;
			public ushort Questions;
			public ushort AnswerRRS;
			public ushort AuthorityRRS;
			public ushort AdditionalRRS;
			public QUESTION_ITEM [] QuestionObject;
			public ANSWER_ITEM [] AnswerObject;
			public AUTHORITY_ITEM [] AuthorityObject;
			public ADDITIONAL_ITEM [] AdditionalObject;

		}


		private PACKET_DNS PDns;
		private string [] FlagsArray = new string[8];
		private string [] Flags2Array = new string[2];

		public PacketDNS()
		{

		}


		private void InitStruct()
		{
			PDns.AdditionalRRS = 0;
			PDns.AnswerRRS = 0;
			PDns.AuthorityRRS = 0;
			PDns.Flags = 0;
			PDns.FlagsStr = "";
			PDns.Questions = 0;
			PDns.TransactionId = 0;

		}

		public string GetTypeString( ushort u )
		{
			string Tmp = "";

			switch( u )
			{
				case Const.TYPE_NB	: Tmp = "NB"; break;
			}

			return Tmp;
		}


		public string GetClassString( ushort u )
		{
			string Tmp = "";

			switch( u )
			{
				case Const.CLASS_INET	: Tmp = "inet"; break;
			}

			return Tmp;
		}

		private string GetOpcodeString( ushort b )
		{
			string Tmp = "", Tmp2 = "";
			int bb = (int) b;
			byte bbb;

			bb >>= 11;
			bb &= 0x0000000f;

			bbb = (byte) bb;

			switch( bb )
			{
				case	0	: Tmp = "Name query"; break;
				case	5	: Tmp = "Registration"; break;
			}

			Tmp += "( " + bb.ToString() + " )";

			if( ( bbb & 8 ) == 8 ) Tmp2 += ".1"; else Tmp2 += ".0";
			if( ( bbb & 4 ) == 4 ) Tmp2 += "1"; else Tmp2 += "0";
			if( ( bbb & 2 ) == 2 ) Tmp2 += "1"; else Tmp2 += "0";
			if( ( bbb & 1 ) == 1 ) Tmp2 += " 1"; else Tmp2 += " 0";

			Tmp = Tmp2 + "... .... .... = Opcode : " + Tmp;

			return Tmp;
		}

		private string GetReplayCodeString( ushort b )
		{
			string Tmp = "", Tmp2 = "";
			byte bb = (byte) b;

			bb &= 0x0f;

			switch( bb )
			{
				case	0	: Tmp = "No Error"; break;
			}

			Tmp += "( " + bb.ToString() + " )";

			if( ( bb & 8 ) == 8 ) Tmp2 += "1"; else Tmp2 += "0";
			if( ( bb & 4 ) == 4 ) Tmp2 += "1"; else Tmp2 += "0";
			if( ( bb & 2 ) == 2 ) Tmp2 += "1"; else Tmp2 += "0";
			if( ( bb & 1 ) == 1 ) Tmp2 += "1"; else Tmp2 += "0";

			Tmp = ".... .... .... " + Tmp2 + " = Reply Code : " + Tmp;

			return Tmp;
		}

		private void GetFlagsString( ushort u )
		{
			string Tmp = "";

			if( ( u & Const.FLAGS_RESPONSE ) == Const.FLAGS_RESPONSE )
				Tmp = "1... .... .... .... = Response : Message is a response";
			else
				Tmp = "0... .... .... .... = Response : Message is a query";

			FlagsArray[0] = Tmp;

			Tmp = GetOpcodeString( u );
			FlagsArray[1] = Tmp;

			if( ( u & Const.FLAGS_AUTHORITATIVE ) == Const.FLAGS_AUTHORITATIVE )
				Tmp = ".... .1.. .... .... = Authoritative : Server is an authority for domain";
			else
				Tmp = ".... .0.. .... .... = Authoritative : Server is not an authority for domain";

			FlagsArray[2] = Tmp;

			if( ( u & Const.FLAGS_TRUNCATED ) == Const.FLAGS_TRUNCATED )
				Tmp = ".... ..1. .... .... = Truncated : Message is truncated";
			else
				Tmp = ".... ..0. .... .... = Truncated : Message is not truncated";

			FlagsArray[3] = Tmp;

			if( ( u & Const.FLAGS_RECURSION_DESIRED ) == Const.FLAGS_RECURSION_DESIRED )
				Tmp = ".... ...1 .... .... = Recursion Desired : Do query recursively";
			else
				Tmp = ".... ...0 .... .... = Recursion Desired : Don't do query recursively";

			FlagsArray[4] = Tmp;

			if( ( u & Const.FLAGS_RECURSION_AVAILABLE ) == Const.FLAGS_RECURSION_AVAILABLE )
				Tmp = ".... .... 1... .... = Recursion Available : Server can do recursive queries";
			else
				Tmp = ".... .... 0... .... = Recursion Available : Server cann't do recursive queries";

			FlagsArray[5] = Tmp;

			if( ( u & Const.FLAGS_BROADCAST ) == Const.FLAGS_BROADCAST )
				Tmp = ".... .... ...1 .... = Broadcast : Packet is broadcast";
			else
				Tmp = ".... .... ...0 .... = Broadcast : Packet is not broadcast";

			FlagsArray[6] = Tmp;

			Tmp = GetReplayCodeString( u );
			FlagsArray[7] = Tmp;

		}

		private void GetFlags2String( ushort u )
		{
			string Tmp = "";
			byte b;

			if( ( u & (ushort) 0x80 ) == 0x80 )
				Tmp = "1... .... .... .... = Not unique name";
			else
				Tmp = "0... .... .... .... = Unique name";

			Flags2Array[0] = Tmp;

			int uu = (int) u;

			uu >>= 13;
			uu &= 0x00000003;
			b = (byte) uu;

			if( b == 0 ) Tmp = ".00. .... .... .... = B-node";
			else if( b == 1 ) Tmp = ".01. .... .... .... = ?";
			else if( b == 2 ) Tmp = ".10. .... .... .... = ?";
			else if( b == 3 ) Tmp = ".11. .... .... .... = ?";

			Flags2Array[1] = Tmp;

		}


		public TreeNode GetDNSNode( PACKET_DNS PDns )
		{
			TreeNode mNode;
			TreeNode mNode1;
			TreeNode mNode2;
			string Tmp = "";
			int i = 0;

			mNode = new TreeNode();
			mNode.Text = "DOMAIN NAME SERVICE";

			Tmp = "Transaction Id :" + Function.ReFormatString( PDns.TransactionId , null );
			mNode.Nodes.Add( Tmp );

			mNode1 = new TreeNode();
			mNode1.Text = "Flags :" + Function.ReFormatString( PDns.Flags , null );
			GetFlagsString( PDns.Flags );
			for( i = 0; i < 8; i ++ )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -