Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <netinet/in.h>
- #include <netinet/ip.h>
- #include <netinet/ip_icmp.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <sys/signal.h>
- #include <string.h>
- #define DEFDATALEN 56
- #define MAXIPLEN 60
- #define MAXICMPLEN 76
- static char *hostname = NULL;
- static int in_cksum(unsigned short *buf, int sz)
- {
- int nleft = sz;
- int sum = 0;
- unsigned short *w = buf;
- unsigned short ans = 0;
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
- if (nleft == 1) {
- *(unsigned char *) (&ans) = *(unsigned char *) w;
- sum += ans;
- }
- sum = (sum >> 16) + (sum & 0xFFFF);
- sum += (sum >> 16);
- // ans = .sum;
- ans = ~sum;
- return (ans);
- }
- static void noresp(int ign)
- {
- printf("No response from %s\n", hostname);
- exit(0);
- }
- static void ping(const char *host)
- {
- struct hostent *h;
- struct sockaddr_in pingaddr;
- struct icmp *pkt;
- int pingsock, c;
- char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
- if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */
- perror("ping: creating a raw socket");
- exit(1);
- }
- /* drop root privs if running setuid */
- setuid(getuid());
- memset(&pingaddr, 0, sizeof(struct sockaddr_in));
- pingaddr.sin_family = AF_INET;
- if (!(h = gethostbyname(host))) {
- fprintf(stderr, "ping: unknown host %s\n", host);
- exit(1);
- }
- memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
- hostname = h->h_name;
- pkt = (struct icmp *) packet;
- memset(pkt, 0, sizeof(packet));
- pkt->icmp_type = ICMP_ECHO;
- pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
- c = sendto(pingsock, packet, sizeof(packet), 0,
- (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
- if (c < 0 || c != sizeof(packet)) {
- if (c < 0)
- perror("ping: sendto");
- fprintf(stderr, "ping: write incomplete\n");
- exit(1);
- }
- close(pingsock);
- return;
- }
- int main ()
- {
- //printf( "Well fuck:" );
- int ip1; // X.X.X.1
- int ip2; // X.X.1.X
- int ip3; // X.1.X.X
- int ip4; // 1.X.X.X
- ip1 = 1;
- ip2 = 1;
- ip3 = 1;
- ip4 = 50;
- char s1[6];
- char s2[6];
- char s3[6];
- char s4[6];
- char full[50];
- while(1){
- ip1++;
- if(ip1 == 254){
- ip2++;
- ip1 = 0;
- }
- if(ip2 == 254){
- ip3++;
- ip2 = 0;
- printf( "\nIP: %s", full );
- }
- if(ip3 == 254){
- ip4++;
- ip3 = 0;
- }
- sprintf(s1, "%d", ip1);
- sprintf(s2, "%d", ip2);
- sprintf(s3, "%d", ip3);
- sprintf(s4, "%d", ip4);
- /*
- strcpy( full, s1 );
- strcat( full, "." );
- strcpy( full, s2 );
- strcat( full, "." );
- strcpy( full, s3 );
- strcat( full, "." );
- strcpy( full, s4 ); */
- sprintf( full, "%s.%s.%s.%s", s4, s3, s2, s1 );
- //printf( "\nIP: %s", full );
- ping (full);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement