hola principe_azul.
bueno al igual que tu no lelvo mucho con esto de los sockets pero mira ya pude correr tu codigo espero que esto te ayude.
Código C:
Ver original#include <winsock2.h>
#include <windows.h>
#include <iostream>
#pragma comment(lib, "Ws2_32.lib")
using namespace std;
char IP[20];
int startPort, endPort, err, nret;
int main()
{
struct sockaddr_in conect;
SOCKET iSocket;
SOCKADDR_IN Info;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0 )
{
cout << "Winsock Error, Exiting..." << endl;
cin.get();
return 0;
}
cout << "Target IP: ";
cin>>IP;
cout << "Starting Port: ";
cin>>startPort;
cout << "End Port: ";
cin>>endPort;
cin.ignore();
cout << endl << endl << "Scanning..." << endl << endl;
for(int i=startPort; i < endPort; i++)
{
//iSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
iSocket = socket(AF_INET, SOCK_STREAM, 0);
Info.sin_family = AF_INET;
Info.sin_port = htons(startPort);
nret = connect(iSocket, (struct sockaddr *)&conect, sizeof(struct sockaddr));
// error is for line above
if(nret != SOCKET_ERROR)
{
cout << "Port " << i << " - OPEN! " << endl;
}
//temp++;
closesocket(iSocket);
}
cout << endl << "Finished With Scan..." << endl;
cin.get();
WSACleanup();
}
saludos.