Ejemplo n.º 1
0
void scan_r(char *ip,int s_port,int e_port,int *result)
{
    int count = 0;
    for (int i = s_port; i <= e_port; i++) {
        printf("开始扫描%d号端口\n",i);
        
        int r = -1;
        if ((r=conn_nonb(ip, i, 100)) == 0) {
            count++;
            result[count]= i;
        }
        
    }
    result[0] = count;
   
}
Ejemplo n.º 2
0
void scan_r(char *ip,int s_port,int e_port,int *result)
{
    int count = 0;
    for (int i = s_port; i <= e_port; i++) {
        //printf("scan %d port\n",i);
		;

        int r = -1;
        if ((r=conn_nonb(ip, i, TIMEOUT)) == 0) {
            count++;
            result[count]= i;
        }

    }
    result[0] = count;

}
Ejemplo n.º 3
0
int
open_client_socket(const char* hostname, unsigned short int Port)
{
        int sockfd;
        struct addrinfo hints, *servinfo, *p;
        int rv;
        char port[8];
        memset(&hints, 0, sizeof hints);
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_flags = AI_PASSIVE;

        sprintf(port, "%hd", Port);
        if((rv = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) {
                fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
                return -1;
        }

        for(p = servinfo; p != NULL; p = p->ai_next) {
                if((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
                        perror("socket");
                        continue;
                }

                if(conn_nonb(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
                        close(sockfd);
                        perror("conn_nonb");
                        printf("host:%s:%s\n", hostname, port);
                        continue;
                }
                break;
        }
        if (p == NULL) {
                freeaddrinfo(servinfo);
                return -1;
        }
        freeaddrinfo(servinfo);
        return sockfd;
}
Ejemplo n.º 4
0
int main(int argc, const char * argv[])
{
    
    // insert code here...
    if (argc < 4) {
        printf("参数错误,正确命令:扫描的IP地址 开始端口 结束端口 [线程数]\n");
        return 0;
    }
    printf("端口扫描开始\n");
    
    //int fd[65535];
    char *ip = argv[1];
    int s_port = atoi(argv[2]);
    int e_port = atoi(argv[3]);
    int open[65535];
    int count = 0;
    
    if(argc == 5)
    {
        //使用多线程方式
        int ts = atoi(argv[4]);
        res = (int **)malloc(sizeof(int*)*ts);
        mulite_thread_run(ip, s_port, e_port,ts);
    }else{
        //使用单线程
        for (int i = s_port; i <= e_port; i++) {
            printf("开始扫描%d号端口\n",i);
            int r = -1;
            if ((r=conn_nonb(ip, i, 100)) == 0) {
                open[count] = i;
                count++;
            }
        }
    }
    
    
    return 0;
}
Ejemplo n.º 5
0
int main(int argc, const char * argv[])
{

    // insert code here...
    if (argc < 4) {
        printf("arg input error,plz use: target_ip start_port end_port [theads num]\n");
        return 0;
    }
    printf("----start----\n");

    //int fd[65535];
    char *ip = argv[1];
    int s_port = atoi(argv[2]);
    int e_port = atoi(argv[3]);
    int open[65535];
    int count = 0;

    if(argc == 5)
    {
        //multiple threads
        int ts = atoi(argv[4]);
        res = (int **)malloc(sizeof(int*) * ts);
        mulite_thread_run(ip, s_port, e_port,ts);
    }else{
        //single thread
        for (int i = s_port; i <= e_port; i++) {
            //printf("scan %d port\n",i);
            int r = -1;
            if ((r = conn_nonb(ip, i, TIMEOUT)) == 0) {
                open[count] = i;
                count++;
            }
        }
    }


    return 0;
}