- UID
- 2285
- 精华
- 积分
- 513
- 威望
- 点
- 宅币
- 个
- 贡献
- 次
- 宅之契约
- 份
- 最后登录
- 1970-1-1
- 在线时间
- 小时
|
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <winsock.h>
-
- #pragma comment(lib,"ws2_32.lib")
-
- //定义DNS数据 ID tag numq numa numa1 numa2
- char DNS_DATA[]={0x12,0x34,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x03,0x77,0x77,0x77,0x06,0x30,0x78,0x61,0x61,0x35,0x35,0x03,0x63,0x6F,0x6d,0x00,//03 www 06 0xaa55 03 com 00
- 0x00,0x01,0x00,0x01};//前两字节为1表示A记录; 后两字节为1表示DNS_HDR+域名+DNS_QER
-
-
- int main(int argc,char* argv[])
- {
- WORD socketVersion = MAKEWORD(2,2);
- WSADATA wsaData;
- if(WSAStartup(socketVersion, &wsaData) != 0)
- {
- printf("error");
- return 0;
- }
- //创建UDP通信套接字
- SOCKET sclient = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-
- SOCKADDR_IN sin;
- sin.sin_family = AF_INET;
- sin.sin_port = htons(53);//DNS远程端口固定为53
- sin.sin_addr.S_un.S_addr = inet_addr("114.114.114.114");//DNS服务器IP地址,可以填网关地址如(192.168.0.1)
-
- //发送域名数据
- sendto(sclient, DNS_DATA, sizeof(DNS_DATA), 0, (SOCKADDR *)&sin, sizeof(sin));
-
- char recvData[255];
- int ret = recv(sclient, recvData, 255, 0);//等待接收数据
- if(ret > 0)//收到大于0的数据
- {
- for(int i=0;i<ret;i++)//以16进制格式打印出来
- {
- printf("%02X ",(unsigned char)recvData[i]);
- }
- }
-
- closesocket(sclient);
- WSACleanup();
- return 0;
- }
复制代码
返回:
12 34 81 80 00 01 00 01 00 00 00 00 03 77 77 77 06 30 78 61 61 35 35 03 63 6F 6D
00 00 01 00 01 C0 0C 00 01 00 01 00 01 42 00 00 04 8B C7 98 76
可以看到,8B C7 98 76就是为www.0xaa55.com的IP地址:139.199.152.118
|
|