注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

K8拉登哥哥's Blog

K8搞基大队[K8team] 信息安全 网络安全 0day漏洞 渗透测试 黑客

 
 
 

日志

 
 

C# ICMP封包监听 实测有些抓不到 不准 真的不适合写马  

2014-03-31 08:03:33|  分类: C#.NET |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace icmp_capture
{
    class Program
    {
        static void Main(string[] args)
        {
            IPEndPoint ipMyEndPoint = new IPEndPoint(IPAddress.Any, 0);
            EndPoint myEndPoint = (ipMyEndPoint);
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);
            socket.Bind(myEndPoint);
            while (true)
            {

                /*                
                //SEND SOME BS (you will get a nice infinite loop if you uncomment this)
                var udpClient = new UdpClient("192.168.2.199", 666);   //**host must exist if it's in the same subnet (if not routed)**              
                Byte[] messagebyte = Encoding.Default.GetBytes("hi".ToCharArray());                
                int s = udpClient.Send(messagebyte, messagebyte.Length);
                */

                Byte[] ReceiveBuffer = new Byte[256];
                var nBytes = socket.ReceiveFrom(ReceiveBuffer, 256, 0, ref myEndPoint);
                
                //if (ReceiveBuffer[20] == 3)// ICMP type = Delivery failed
                //{
                //    Console.WriteLine("Delivery failed");
                //    Console.WriteLine("Returned by: " + myEndPoint.ToString());
                //    Console.WriteLine("Destination: " + ReceiveBuffer[44] + "." + ReceiveBuffer[45] + "." + ReceiveBuffer[46] + "." + ReceiveBuffer[47]);
                //    Console.WriteLine("---------------");
                //}
                //else
                //{
                //    Console.WriteLine("Some (not delivery failed) ICMP packet ignored");
                    
                //}
                Encoding encoding = Encoding.UTF8;
                int dataLength = socket.ReceiveFrom(ReceiveBuffer, ref myEndPoint);
                var dataPackage = encoding.GetString(ReceiveBuffer, 0, dataLength);
                Console.WriteLine(dataPackage);
            }

        }
    }
}
  评论这张
 
阅读(882)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016