📄 rdns.c
字号:
// this a program i wrote awhile ago and modified to only check if an ip// is resolvable and if it is, print it . . . -jsbach#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netdb.h>#include <netinet/in.h>#include <arpa/inet.h>int printhost(char *host);void class_a(char *ip);void class_b(char *ip);void class_c(char *ip);main(int argc, char **argv) {char ch;if ( argc < 3 ) { printf("usage: %s -abc ip_address example: %s -c 206.171.90 or %s -b 206.171 or %s -a 206\n", argv[0], argv[0], argv[0], argv[0]); exit(1); }ch=getopt(argc,argv,"abc"); switch(ch) { case 'a': { class_a(argv[2]); break; } case 'b': { class_b(argv[2]); break; } case 'c': { class_c(argv[2]); break; } }}int printhost(char *host){ struct in_addr *ip; struct hostent *hp; if (inet_aton((char *)host, (struct in_addr *)&ip) == 0) { printf("invalid ip\n"); exit(0); } /* // htonl(ip->s_addr); */ hp = gethostbyaddr((char *)&ip, sizeof(struct in_addr),AF_INET); if (hp != NULL) { printf("%s\n", host); }}void class_a(char *ip){char a[3], b[3], ipstring[32];int count,count1,count2, ca;/* parse the ip address */for (count=0; count < 5; count++) { if (ip[count] == '.') break; a[count]=ip[count]; }ca=atoi(a);for(count=255; count > 0; count--) { for(count1=255; count1 > 0; count1--) { for(count2=255; count2 > 0; count2--) { sprintf(ipstring, "%d.%d.%d.%d",ca, count, count1, count2); printhost(ipstring); fflush(stdout); } } }}void class_b(char *ip){ /* PARSING THE IP AND PUTTING IT IN INT'S CA AND CB "!!!" */char a[3], b[3], ipstring[32];int count,count2, ca, cb;/* parse the ip address */for (count=0; count < 5; count++) { if (ip[count] == '.') break; a[count]=ip[count]; }ca=atoi(a);count++;for (count2=0; count < 8; count++) { if (ip[count] == '\0') break; b[count2]=ip[count]; count2++; }strcat(b, "\0");cb=atoi(b);/* WE ARE NOW DONE PARSING Z IP ADDRESS */for(count=0; count < 255; count++) { for(count2=0; count2 < 255; count2++) { sprintf(ipstring, "%d.%d.%d.%d", ca, cb, count, count2); printhost(ipstring); fflush(stdout); } }}void class_c(char *ip){char a[3], b[3], c[3], ipstring[32];int count,count2, count3, ca, cb, cc;/* parse the ip address */for (count=0; count < 5; count++) { if (ip[count] == '.') break; a[count]=ip[count]; }ca=atoi(a);count++;for (count2=0; count < 8; count++) { if (ip[count] == '.') break; b[count2]=ip[count]; count2++; }count++;for(count3=0; count < 15; count++) { if(ip[count] == '\0') break; c[count3]=ip[count]; count3++; }strcat(c, "\0");cb=atoi(b);cc=atoi(c);for (count=255; count > 0; count--) { sprintf(ipstring, "%d.%d.%d.%d", ca, cb, cc, count); printhost(ipstring); fflush(stdout); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -