#include
<
cstdlib
>
#include
<
iostream
>
#include
<
winsock2.h
>
#pragma
comment(lib,"WS2_32.lib")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using
namespace
std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void
showhelp()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
...
{
cout<<" 神州数码消息传送器 "<<endl;
cout<<" 〓使用说明〓 "<<endl;
cout<<""<<endl;
cout<<"help 显示使用帮助"<<endl;
cout<<"ip 输入目标IP地址"<<endl;
cout<<"msg 开始发送信息,每次回车发送一次,输入exit退出信息发送模式"<<endl;
cout<<"msgn 向指定的IP发送多次消息"<<endl;
cout<<"IP2IP 向一个地址段发送信息"<<endl;
cout<<"exit 退出程序"<<endl<<endl<<endl;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int
main(
int
argc,
char
*
argv[])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
...
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*
神州数码消息传送器
使用说明
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
help 显示使用帮助
ip 输入目标IP地址
msg 开始发送信息,每次回车发送一次,输入exit退出信息发送模式
exit 退出程序
*/
char cmd[255];
char ip[16];
char msg[255];
int flag(0);
int temp;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WSADATA wsaData;
BYTE minorVer=2;
BYTE majorVer=2;
WORD sockVersion=MAKEWORD(minorVer,majorVer);
if(::WSAStartup(sockVersion,&wsaData)!=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{exit(0);};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SOCKET s=socket(AF_INET,SOCK_DGRAM,0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sockaddr_in sin ;
sin.sin_family=AF_INET;
sin.sin_port=htons(10060);
sin.sin_addr.S_un.S_addr=inet_addr("192.168.0.1");
showhelp();
cout<<"[DIGI]#";
while(cin>>cmd)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
flag=0;
if(strcmp(cmd,"help")==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
showhelp();
flag=1;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(strcmp(cmd,"ip")==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
cout<<"请输入目标机器的IP地址:";
cin>>ip;
sin.sin_addr.S_un.S_addr=inet_addr(ip);
flag=1;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(strcmp(cmd,"msg")==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
cout<<"开始发送消息..."<<endl;
while(cin>>msg)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if(strcmp(msg,"exit")!=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
sendto(s,msg,strlen(msg),0,(sockaddr*)&sin,sizeof(sin));
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
break;
}
}
flag=1;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(strcmp(cmd,"msgn")==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
int cnt;
cout<<"请输入要发送的信息:";
cin>>msg;
cout<<"请输入要发送的次数:";
cin>>cnt;
if(cnt<0)cnt=0;
for(int i=0;i<cnt;i++)
sendto(s,msg,strlen(msg),0,(sockaddr*)&sin,sizeof(sin));
flag=1;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//下面是各隐藏的方法
if(strcmp(cmd,"IP2IP")==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
in_addr ip1,ip2;
char iptemp[16];
cout<<"请输入起始IP:";
cin>>iptemp;
ip1.S_un.S_addr=inet_addr(iptemp);
cout<<"请输入中止IP:";
cin>>iptemp;
ip2.S_un.S_addr =inet_addr(iptemp);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"请输入要发送的字符串:";
cin>>msg;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(unsigned long i=ntohl(ip1.S_un.S_addr);i<=ntohl(ip2.S_un.S_addr);i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
sin.sin_addr.S_un.S_addr=htonl(i);
cout<<inet_ntoa(sin.sin_addr)<<endl;
sendto(s,msg,strlen(msg),0,(sockaddr*)&sin,sizeof(sin));
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"发送完毕!"<<endl;
flag=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(strcmp(cmd,"exit")==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
cout<<"谢谢使用!"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(flag==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
showhelp();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<endl<<"[DIGI]#";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
神州数码消息传送器
因为神州数码客户端在UDP-10060监听消息并弹出提示
我们可以通过向该端口发送UDP数据对目标计算机传送消息,呵呵
程序没有防止内存溢出等的处理,比较简陋
有兴趣的可以继续完善
本程序用VC8编译
禁止将本程序用于恶意用途