#include <WinSock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
#include <stdio.h>
const char* info = "wow.exe ipaddress/hostname port macaddress(xx-xx-xx-xx-xx-xx)\n";
int wmain(int argc,wchar_t** argv)
{
if(argc<4)
{
printf(info);
return -1;
}
WORD wVersionRequested = MAKEWORD(2,2);
WSADATA wsaData;
int err;
err = WSAStartup(wVersionRequested,&wsaData);
ADDRINFOW* addr;
err = GetAddrInfo(argv[1],NULL,NULL,&addr);
if(addr==NULL)
{
printf("get address %S error %d",argv[1],err);
return -1;
}
SOCKET s = socket(addr->ai_family,SOCK_DGRAM,IPPROTO_UDP);//SOCK_STREAM,IPPROTO_TCP);
* (unsigned short*)addr->ai_addr->sa_data = htons(_wtoi(argv[2]));
err = connect(s, addr->ai_addr, addr->ai_addrlen);
char buf[16*6+6];
memset(buf,-1,6);
char mac[6] = {0};
wchar_t* m = argv[3];
for(int i=0; i<12; i++ , m++)
{
if(*m==L'-')m++;
int tmp = *m;
tmp &= 0x4f;
int high,low;
high = (tmp) >> 4;
low = (tmp) & 0x0f;
tmp = ((high * 10) >> 2) + low;
tmp -= low==tmp?0:1;
////if tmp > 0x0f error
mac[i/2] |= ((tmp & 0xf) << (((i+1)%2)*4));
}
for(int i=1; i<17; i++)
memcpy(buf+i*6,mac,6);
err = send(s,buf,6*16+6,NULL);
shutdown(s,SD_BOTH);
closesocket(s);
FreeAddrInfo(addr);
WSACleanup();
return 0;
}