SharpPcap 基本抓包源码

继续,SharpPcap抓包的源码,Test示例,太强大了

 

/// <summary>
              /// Basic capture example
              ///</summary>
              [STAThread]
              public static void Main(string[] args)
              {
                     string ver = Tamir.IPLib.Version.GetVersionString();
                     /* Print SharpPcap version */

                     Console.WriteLine("SharpPcap {0}, Example3.BasicCap.cs", ver);

 
                     /* Retrieve the device list */
                     PcapDeviceList devices = SharpPcap.GetAllDevices();
 
                     /*If no device exists, print error */
                     if(devices.Count<1)
                     {

                            Console.WriteLine("No device found on this machine");

                            return;
                     }
                    
                     Console.WriteLine();

                     Console.WriteLine("The following devices are available on this machine:");

                     Console.WriteLine("----------------------------------------------------");
                     Console.WriteLine();
 
                     int i=0;
 
                     /* Scan the list printing every entry */

                     foreach(PcapDevice dev in devices)

                     {
                            /* Description */

                            Console.WriteLine("{0}) {1}",i,dev.PcapDescription);

                            i++;
                     }
 
                     Console.WriteLine();

                     Console.Write("-- Please choose a device to capture: ");

                     i = int.Parse( Console.ReadLine() );

 
                     PcapDevice device = devices[i];
 

                     //Register our handler function to the 'packet arrival' event

                     device.PcapOnPacketArrival +=

                            new SharpPcap.PacketArrivalEvent( device_PcapOnPacketArrival );
 
                     //Open the device for capturing
                     //true -- means promiscuous mode
                     //1000 -- means a read wait of 1000ms
                     device.PcapOpen(true, 1000);
 
                     Console.WriteLine();

                     Console.WriteLine("-- Listenning on {0}, hit 'Enter' to stop...",

                            device.PcapDescription);
 
                     //Start the capturing process
                     device.PcapStartCapture();
 
                     //Wait for 'Enter' from the user.
                     Console.ReadLine();
 
                     //Stop the capturing process
                     device.PcapStopCapture();
 

                     Console.WriteLine("-- Capture stopped.");

 
                     //Close the pcap device
                     device.PcapClose();
              }
 
              ///<summary>

              /// Prints the time and length of each received packet

              ///</summary>

              private static void device_PcapOnPacketArrival(object sender, Packet packet)

              {
                     DateTime time = packet.PcapHeader.Date;
                     int len = packet.PcapHeader.PacketLength;

                     Console.WriteLine("{0}:{1}:{2},{3} Len={4}",

                            time.Hour, time.Minute, time.Second, time.Millisecond, len);

              }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于SharpPcap抓包实例,不会被游戏屏蔽,自行调节,可代替wpe的抓包工具 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 98 64 0 64 6 147 24 5 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 66 137 136 217 57 80 24 6 5 86 74 34 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 122 64 0 64 6 147 2 21 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 72 137 136 217 138 80 24 65 65 73 224 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 124 64 0 64 6 147 2 19 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 78 137 136 217 155 80 24 65 61 73 205 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 125 64 0 64 6 147 2 18 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 84 137 136 217 219 80 24 65 45 73 151 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 127 64 0 64 6 147 2 16 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 90 137 136 218 30 80 24 65 28 73 95 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 129 64 0 64 6 147 2 14 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 96 137 136 218 125 80 24 65 5 73 17 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 133 64 0 64 6 147 2 10 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 102 137 136 218 206 80 2 4 64 240 72 207 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 134 64 0 64 6 147 2 09 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 108 137 136 219 31 80 24 64 220 72 140 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 136 64 0 64 6 147 2 07 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 114 137 136 219 112 80 2 4 64 200 72 73 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 142 64 0 64 6 147 2 01 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 120 137 136 219 179 80 2 4 64 183 72 17 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 32 143 64 0 64 6 147 2 00 192 168 31 169 118 89 47 200 92 23 39 26 187 161 135 126 137 136 219 246 80 2 4 64 166 71 217 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 39 198 64 0 64 6 140 1 45 192 168 31 169 118 89 47 200 92 23 39 26 187 161 136 247 137 136 248 240 80 2 4 64 126 41 142 0 0 99 3 17 0 1 0 240 180 41 90 211 239 136 99 223 137 167 43 8 0 69 0 0 46 39 209 64 0 64 6 140 1 34 192 168 31 169 118 89 47 200 92 23 39 26 187 161 136 253 137 136 249 65 80 24 64 106 41 75 0 0 99 3 17 0 1 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值