C source code for tcp scanning in linux

Source: Internet
Author: User
In linux, tcp scans C source code-General Linux technology-Linux programming and kernel information. The following is a detailed description. # Include
# Include
# Include
# Include
# Include
# Include
/* # Include */

Int main ()
{
Char ip [30];
Int startport, endport, sockfd, I;
Struct sockaddr_in addr;
Float costtime;
Clock_t start, end;
Printf ("Please enter the Startport \ n ");
Scanf ("% d", & startport );
Printf ("Please enter the Endport \ n ");
Scanf ("% d", & endport );
Printf ("Please enter the IP \ n ");
Scanf ("% s", ip );
If (startport <1 | endport> 65535 | endport {
Printf ("port range error! \ N ");
Return 0;
}
Else
Printf ("Interesting ports % d-% d on % s \ n", startport, endport, ip );
Addr. sin_family = AF_INET;
Addr. sin_addr.s_addr = inet_addr (ip );
Start = clock ();
Printf ("port state \ n ");
For (I = startport; I <= endport; I ++)
{
Sockfd = socket (AF_INET, SOCK_STREAM, 0 );
Addr. sin_port = htons (I );
If (connect (sockfd, (struct sockaddr_in *) & addr, sizeof (struct sockaddr_in) = 0)
{
Printf ("% 5d open \ n", I );
Close (addr );
}
}
End = clock ();
Costtime = (float) (end-start)/CLOCKS_PER_SEC;
Printf ("\ nSmart Nmap finished: % s scanned in % f seconds \ n", ip, costtime );
Return 0;
}

This code is absolutely useful for my experiments. if you have any questions, please leave a message .......

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.