Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: Password Security :: easyscan.c

Easyscan 1.0 A simple full-connection TCP port scanner. This utility lists the servers that open the specified port.




/*=============================================================================
  Simple fullconnect port scanner - Easyscan 1.00
  The Shadow Penguin Security (http://shadowpenguin.backsection.net)
  Written by UNYUN (shadowpenguin@backsection.net)
  =============================================================================
*/
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
/*
#include <netinet/in.h>
#include <netdb.h>
*/

#define     TIMEOUT_V   2       /* Connection Timeout value */
#define     MAX_IPLEN   16

int     sock;

main()
{
    int             portscan(int, char *);
    int             separation(char *,unsigned long *);
    unsigned long   ips,ipe,ip;
    char            buf[MAX_IPLEN],buf2[MAX_IPLEN];
    int             portn;
    FILE            *fp;

    printf("Simple fullconnect port scanner - Easyscan 1.00\n");
    printf("The Shadow Penguin Security, Inc.\n\n");
    printf("Start IP address : ");
    scanf("%s",buf);
    if (separation(buf,&ips)==-1){
        printf("Error : Invalid IP address.\n");
        exit(1);
    }
    printf("End IP address : ");
    scanf("%s",buf2);
    if (separation(buf2,&ipe)==-1){
        printf("Error : Invalid IP address.\n");
        exit(1);
    }
    printf("Port : ");
    scanf("%d",&portn);

    if ((fp=fopen("log.txt","w"))==NULL){
        printf("Can not write log file.\n");
        exit(1);
    }
    fprintf(fp,"Start IP address : %s\n",buf);
    fprintf(fp,"End IP address   : %s\n",buf2);
    fprintf(fp,"Port             : %d\n",portn);
    fprintf(fp,"\n\n");
    for (ip=ips;ip<=ipe;ip++){
        sprintf(buf,"%lu.%lu.%lu.%lu",  ip>>24,
                                        (ip&0x00ff0000)>>16,
                                        (ip&0x0000ff00)>>8,
                                        ip&0x000000ff);
        printf("%15s...",buf);
        fprintf(fp,"%15s...",buf);
        if (portscan(portn,buf)==0){
                printf("Connected!\n");
                fprintf(fp,"Connected!\n");
        }else{
                printf("no\n");
                fprintf(fp,"no\n");
        }
    }
    fclose(fp);
}

int separation(char *ipaddr,unsigned long *ipl)
{
    int             i,j,n;
    char            buf[MAX_IPLEN];
    int             ip[4];
    unsigned long   d;

    for (n=0,j=0,i=0;i<=strlen(ipaddr);i++){
        if (ipaddr[i]=='.' || i==strlen(ipaddr)){
            buf[j]=0;
            ip[n]=atoi(buf);
            if (ip[n]<0 || ip[n]>255) return (-1);
            n++; j=0;
        }else{
            buf[j]=ipaddr[i];
            j++;
        }
    }
    if (n!=4) return (-1);
    d=256;
    *ipl=ip[3]+ip[2]*d+ip[1]*d*d+ip[0]*d*d*d;
    return(0);
}

int   portscan(int port, char *ipaddr)
{
    struct sockaddr_in  addr, server;
    void                timeoutfunc();

    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0){
        printf("Socket creation error");
        return(-1);
    }

    memset((char *) &server, 0, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = htonl(INADDR_ANY);
    server.sin_port = 0;

    if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) {
        close(sock);
        printf("Bind error ");
        return (-2);
    }

    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(ipaddr);
    addr.sin_port = htons(port);

    signal(SIGALRM, timeoutfunc);
    alarm(TIMEOUT_V);

    if (connect(sock,(struct sockaddr *)&addr,sizeof(addr))!=0){
        close(sock);
        return (-3);
    }
    close(sock);
    return (0);
}
void    timeoutfunc()
{
    close(sock);
}


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH