端口扫描程序始终不返回可用的打开端口

时间:2015-06-03 06:30:03

标签: c++ port-scanning

当我运行此代码时,它始终返回没有可用的开放端口。我该如何解决这个问题?

for(y=1; y<20000; y++ ) {
    sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    Info.sin_addr.s_addr = inet_addr(IPaddress);
    Info.sin_family = AF_INET;
    Info.sin_port = htons(y);

    x = connect (sock, NULL, NULL);

    if(x != SOCKET_ERROR ){
        cout << "Port" << y <<  "- OPEN ! " << endl;
    }

    closesocket(sock);
}

WSACleanup();

cout << "Port scan has finished " << endl;
system("pause");

0 个答案:

没有答案