Simple TCP full-connection scan under MACOSX

Source: Internet
Author: User

The principle is very simple, just as the reply is also said to be based on the Connect () function return value: Then the teacher said, this is full connection, cannot scan UDP port bar. Well, I forgot what I said later. In this way, the reply will be finished. Actually didn't ask what, hehe. So easy. And then stick to my code, in fact, according to the online information modification, copyright do not find me. function is everyone's: dd, sticky code ING.

1#include <sys/types.h>2#include <sys/socket.h>3#include <netinet/inch.h>4#include <time.h>5#include <stdio.h>6 7 #defineSP 18 #defineEP 10009 Ten voidmsg () One { Aprintf"Usage:scanner [IP address]\n"); - } -  the intMainintargcChar*argv[]) - {   -    floatCosttime; - clock_t start, end; +     -    intp; +    intSOCKFD;//returns the file descriptor of a socket A    structsockaddr_in my_addr; at    intRenum;//defines the return value of the Connect () function -    if(2!=argc) { - msg (); -        return 0; -    } -  in     //Scan Address Initialization -my_addr.sin_family =af_inet; toMY_ADDR.SIN_ADDR.S_ADDR =htonl (inaddr_any); +Inet_pton (Af_inet, argv[1], &my_addr.sin_addr); -Start =clock (); the      *      for(p = SP; p < EP; p++) $     {Panax NotoginsengMy_addr.sin_port =htons (p); -SOCKFD = socket (Af_inet,sock_stream,0); theRenum = Connect (SOCKFD, (structSOCKADDR *) &my_addr,sizeof(structsockaddr)); +         if(Renum = =0) Aprintf"%d ports Open! \ n", p); the Close (SOCKFD); +     } -  $End =clock (); $Costtime = (float) (End-start)/10000; -printf"Scan Time:%f sec \ n", costtime); -     the    return(0); -}

Simple TCP full-connection scan under MACOSX

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.