shaomiao.cpp
资源名称:scan.rar [点击查看]
上传用户:duocai510
上传日期:2022-01-13
资源大小:1118k
文件大小:1k
源码类别:
扫描程序
开发平台:
Visual C++
- #include <iostream>
- using namespace std;
- #include "winsock2.h"
- #include "string"
- #pragma comment(lib,"WS2_32")
- #include <stdio.h>
- int main(char *argc,char**argv)
- {
- WORD wVersionRequested;
- WSADATA data ;
- wVersionRequested = MAKEWORD( 2, 2 );
- if (WSAStartup(wVersionRequested,&data) != 0)
- {
- exit(0);
- }
- SOCKET sClient;
- sClient = socket(AF_INET,SOCK_STREAM,0);
- if(sClient == INVALID_SOCKET)
- {
- printf("socket() Failed: %dn",WSAGetLastError());
- return -1;
- }
- int i ;
- char ip[20];
- int sport ;
- int eport ;
- cout << "start san...."<<endl;
- cout <<"input san IP and Port:";
- cin >>ip>>sport>>eport;
- for ( i=sport ; i <= eport; i++)
- {
- struct sockaddr_in serv;
- serv.sin_family = AF_INET;
- serv.sin_port = htons(i);
- serv.sin_addr.S_un.S_addr = inet_addr(ip);
- if (connect(sClient,(struct sockaddr*)&serv,sizeof(serv))!= -1)
- {
- cout<<"open port:"<<i<<endl;
- cout<<"continue....."<<endl;
- }
- else
- {
- cout <<" close port: "<<i<<endl;
- cout <<"continue"<<endl;
- }
- }
- closesocket(sClient);
- WSACleanup();
- return 0;
- }