what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

soupscan.c

soupscan.c
Posted Aug 17, 1999
Authored by Ambient Empire

Soup Scanner is a fast, simple, and efficient Class C domain scanner. It scans an entire Class C type domain for a specified port and simply dumps resulting hosts to the terminal window.

tags | tool, scanner
systems | unix
SHA-256 | c51ce4d9ce43a4faa8c84bf3e1d7a247f767bffc53174a999766c871472d146f

soupscan.c

Change Mirror Download
/* 20 Second Soup Scanner
* Ambient Empire
* by aempirei
* inspired by bind's `propecia.c'
* slower but cleaner
*/

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>

#define SA struct sockaddr
#define SIN_LEN sizeof(struct sockaddr_in)
#define IPV4_ADDRLEN 16

void ShowHelp(char *, char *);

/* confine the shared forked code for niceness */
int ConnectCheck(struct sockaddr_in, int, int);

/* this be wrapper functions pulled from other ambient empire code */
const char *ipv4_ntop(int, const void *, char *, size_t);
const char *ipv4_showname(int , const void *, char *, size_t);

int main(int argc, char *argv[]) {
int i, status,
DestPort = 139,
Children = 128,
Timeout = 7,
Resolve = 0;
char DestIP[15];
char *NetworkID;
char c;

struct sockaddr_in DestAddress;

if(argc < 2) ShowHelp(argv[0], "ERROR: invalid number of arguments");

NetworkID = argv[1];
sprintf(DestIP, "%s.255", NetworkID);
if(!inet_aton(DestIP, &DestAddress.sin_addr))
ShowHelp(argv[0], "ERROR: invalid network ID");

opterr = 0;
while((c = getopt(argc, argv, "Rp:c:t:")) != -1) {
switch(c) {
case 'R': Resolve = -1; break;
case 'p': DestPort = atoi(optarg); break;
case 'c': Children = atoi(optarg); break;
case 't': Timeout = atoi(optarg); break;
case '?': ShowHelp(argv[0], "ERROR: unrecognized option"); break;
}
}

if(DestPort < 1) ShowHelp(argv[0], "ERROR: invalid target port");
if(Children < 1) ShowHelp(argv[0], "ERROR: invalid number of children");
if(Timeout < 1) ShowHelp(argv[0], "ERROR: invalid timeout");

fprintf(stderr, "Scanning %s.*:%i -- %i children -- %i second timeout\n\n",
NetworkID, DestPort, Children, Timeout);

DestAddress.sin_family = AF_INET;
DestAddress.sin_port = htons(DestPort);

for(i = 0; i < Children; i++) {

sprintf(DestIP, "%s.%d", NetworkID, i);
inet_aton(DestIP, &DestAddress.sin_addr);
if(!fork()) ConnectCheck(DestAddress, Timeout, Resolve);
}

for(i = Children + 1; i < 256; i++) {
wait(&status); /* wait till a child dies to make another */

sprintf(DestIP, "%s.%d", NetworkID, i);
inet_aton(DestIP, &DestAddress.sin_addr);
if(!fork()) ConnectCheck(DestAddress, Timeout, Resolve);
}

for(;;) {
if((waitpid(-1, &status, WNOHANG) == -1) && (errno == ECHILD))
exit(EXIT_SUCCESS);
}
}

int ConnectCheck(struct sockaddr_in DestAddr, int Timeout, int Resolve) {
int result;
int SocketFD;
char Hostname[60];

if((SocketFD = socket(AF_INET, SOCK_STREAM, 0)) < 0) exit (EXIT_FAILURE);

alarm(Timeout);

result = connect(SocketFD, (SA *)&DestAddr, SIN_LEN);

if (!result) {
if(Resolve) printf("%s\n", ipv4_showname(AF_INET,
&DestAddr.sin_addr.s_addr,
Hostname, 59));
else printf("%s\n", ipv4_ntop(AF_INET,
&DestAddr.sin_addr.s_addr,
Hostname, 59));
close(SocketFD);
}

exit(EXIT_SUCCESS);
}

const char *
ipv4_ntop(int family, const void *addrptr, char *strptr, size_t len) {
const u_char *p = (const u_char *)addrptr;

if(family == AF_INET) {
char temp[IPV4_ADDRLEN];

snprintf(temp, sizeof(temp), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
if(strlen(temp) >= len) {
errno = ENOSPC;
return(NULL);
}
strcpy(strptr, temp);
return(strptr);
}
errno = EAFNOSUPPORT;
return(NULL);
}

const char *
ipv4_showname(int family, const void *addrptr, char *strptr, size_t len) {
struct hostent *hentry;

size_t aflen;

if(family == AF_INET) aflen = 4;
else {
errno = EAFNOSUPPORT;
return(NULL);
}

if((hentry = gethostbyaddr(addrptr, aflen, family)) != NULL) {
if(strlen(hentry->h_name) < len) {
strcpy(strptr, hentry->h_name);
return(strptr);
}
}

return(ipv4_ntop(family, addrptr, strptr, len));
}

void ShowHelp(char *argv0, char *ErrMsg) {
printf("%s\n\n", ErrMsg);
printf("Usage: %s <X.X.X> [-p <port>] "
"[-c <children>] "
"[-t <timeout>] [-R]\n", argv0);
printf(" <X.X.X> \tclass c network ID\n");
printf(" [-p <port>] \ttarget tcp/ip port number\n");
printf(" [-c <children>]\tmaximum simultaneous children\n");
printf(" [-t <timeout>] \tseconds before connection timeout\n");
printf(" [-R] \tresolve IPs to hostnames\n");

exit (EXIT_FAILURE);
}

Login or Register to add favorites

File Archive:

October 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Oct 1st
    39 Files
  • 2
    Oct 2nd
    23 Files
  • 3
    Oct 3rd
    18 Files
  • 4
    Oct 4th
    20 Files
  • 5
    Oct 5th
    0 Files
  • 6
    Oct 6th
    0 Files
  • 7
    Oct 7th
    17 Files
  • 8
    Oct 8th
    66 Files
  • 9
    Oct 9th
    25 Files
  • 10
    Oct 10th
    20 Files
  • 11
    Oct 11th
    21 Files
  • 12
    Oct 12th
    0 Files
  • 13
    Oct 13th
    0 Files
  • 14
    Oct 14th
    14 Files
  • 15
    Oct 15th
    49 Files
  • 16
    Oct 16th
    28 Files
  • 17
    Oct 17th
    23 Files
  • 18
    Oct 18th
    10 Files
  • 19
    Oct 19th
    0 Files
  • 20
    Oct 20th
    0 Files
  • 21
    Oct 21st
    0 Files
  • 22
    Oct 22nd
    0 Files
  • 23
    Oct 23rd
    0 Files
  • 24
    Oct 24th
    0 Files
  • 25
    Oct 25th
    0 Files
  • 26
    Oct 26th
    0 Files
  • 27
    Oct 27th
    0 Files
  • 28
    Oct 28th
    0 Files
  • 29
    Oct 29th
    0 Files
  • 30
    Oct 30th
    0 Files
  • 31
    Oct 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close