Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- int sz = 0;
- char* makeq(char* host, int id) {
- static char query[2048];
- memset(query,(char) 0, sizeof(query));
- query[0] = id;
- query[1] = id;
- query[2] = 1;
- query[5] = 1;
- strcat(host, ".");
- int j = 0, qptr = 12;
- for (int i = 0; i < strlen(host); i++) {
- if (host[i] == '.') {
- query[qptr++] = i - j;
- for (int q = j; q < i; q++){
- query[qptr++] = host[q];
- }
- j = i + 1;
- }
- }
- query[qptr + 2] = 1;
- query[qptr + 4] = 1;
- sz = qptr + 5;
- return query;
- }
- int main(int argc, char* argv[]) {
- unsigned char buff[2048];
- int sock = socket(AF_INET, SOCK_DGRAM, 0);
- struct sockaddr_in addr = {
- .sin_family = AF_INET,
- .sin_addr = inet_addr("8.8.8.8"),
- .sin_port = htons(53)
- };
- int id = 96;
- while(scanf("%s", buff) > 0) {
- id++;
- unsigned char* message = makeq(buff, id);
- int x = sendto(sock,
- message, sz,
- 0,
- (const struct sockaddr*) &addr,
- sizeof(addr));
- x = recvfrom(sock,
- message, 2048,
- 0, NULL, NULL);
- printf("%d.%d.%d.%d\n", message[sz + 12], message[sz + 13], message[sz + 14], message[sz + 15]);
- }
- close(sock);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement