当前位置:编程学习 > asp >>

模仿Net Send命令的匿名消息发送器

最近没事在邪八溜达,看到个sunlion发的老帖子,evilsun匿名信使发送器, 就是模仿windows中的net send命令在局域网中发送消息,接收消息的计算机必须开启了Messenger服务才能正确收到消息,开启messenger的命令是net start messenger。由于当时sunlion没给出代码,反正我也闲着无聊,就随便写了个玩玩,代码很简单,用到的核心函数是NetMessageBufferSend函数。

  以下代码在Windows Xp / Windows 2000 + VC6.0下测试成功。

CODE:

/*
*   功能:模仿Net Send 命令发消息
*
*   文件:SendMsg.cpp
*
*   编码:Unicorn
*
*   日期:2006年7月4日
*/

#include
#include
#include
#include
#include
#include

#pragma comment(lib, "Netapi32.lib")   // 加载Netapi32.lib库

void Usage(wchar_t *AppName)
{

  char szInformation[] = "欢迎使用UNI匿名消息发送器 V1.0 Coding By Unicorn 2006/7/4";
  char szParam[] = "参数说明: 参数不可省略,是目的机器的IP地址. 参数不可省略,是发送端的名称,这里可以随便填写. 参数不可省略,要发送的信息. [Count]参数可以省略,发送消息的次数,默认为1次.";

  printf("========================================================= ");
  printf("%s ", szInformation);
  printf("========================================================= ");
  printf("Usage: %s [Count] ", AppName);
  printf("%s ", szParam);
}

void wmain(int argc, wchar_t *argv[])
{  
  // 参数不满4个或者5个的话就出现帮助信息
  if ((argc<4) || (argc>5))
  {
    Usage(argv[0]);  
    return;
  }

  wchar_t *DesIp = argv[1];
  wchar_t *SouIp = argv[2];
  wchar_t *Msg = argv[3];
  const wchar_t *wCount = argv[4];
  int count = _wtoi(wCount);

  if (count == 0)
  {
    count = 1;
  }
 
  int nCount = count;

  printf("Sending ");

  while (count--)
  {
    // 发送函数
    int nRet = NetMessageBufferSend(NULL, DesIp, SouIp, (LPBYTE)Msg, sizeof(Msg));

    if (nRet != NERR_Success)
    {
        switch(nRet)
        {
          case ERROR_ACCESS_DENIED:
            printf("The user does not have access to the requested information. ");
            break;

          case ERROR_INVALID_PARAMETER:
            printf("The specified parameter is invalid. ");
            break;

          case ERROR_NOT_SUPPORTED:
            printf("This network request is not supported. ");
            break;

          case NERR_NameNotFound:
            printf("The user name could not be found. ");
            break;

          case NERR_NetworkError:
            printf("A general failure occurred in the network hardware. ");
            break;
         
          default:
            break;
        }

        break;
    }
    printf("...");
  }
 
  printf(" 总共发送了%d次 ", nCount);
}

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,