Frage von Kravag, 18

Wieso stürzt das Programm immer ab?

Dieses C++ Programm, das zum Scannen von Ports gedacht ist, stürzt immer wieder am Ende ab, wieso? hier der Code:

#include <winsock2.h>
 #include <iostream>
#include <windows.h>
using namespace std;

char IP[20];
int start, end, temp, err, nret, open, offen;
SOCKET sock;
SOCKADDR_IN Info;
WSADATA wsadata;

int main()
{
system("color C");
   err = WSAStartup(MAKEWORD(2, 2), &wsadata);
   if(err != 0)
 {
      cout << "Error with winsock. Will Now Exit." << endl;
  cin.get();
  return 0;
 }

cout << "Target IP: ";
cin>>IP;
cout << "Starting Port: ";
cin>>start;
cout << "End Port: ";
cin>>end;

cin.ignore();

cout << endl << endl << "Hit return button to run Port Scan!" << endl;
cin.get();
open = 0;

temp = start;
while(temp < end)
{
  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 
  Info.sin_family = AF_INET;
  Info.sin_port = htons(start);
  nret = connect(sock, NULL, NULL);
  if(nret != SOCKET_ERROR)
  {
     cout << "Port " << temp << " - OPEN! " << endl;
     offen = temp;
     open++;
  }
  else
  {
    cout << "Port closed " << temp << endl;
  }
  temp++;
  closesocket(sock);
}

if(open != 0)
{
    Beep(3000,1000);
    cout << "===================================================================\n";
    cout << "               Warnig!\n";
    cout << "an open Port can be used to get in to your computer\n";
    cout << "You should close the port, if it isnt used by you!\n";
}

cout << "=======================================================================\n";
cout << endl << "Finished With Scaning Ports between: " << endl;
cout << "  " << start << endl;
cout << " and\n";
cout << "  " << end << endl;
cout << "Target IP was: " << IP << endl;
cout << "Open Ports: " << open <<endl;
cout << "Open Port: " << offen << endl;
cout << "=======================================================================\n";
 
cin.get();
return 0;

}

Antwort
von DrDralle, 11

Kuck da:

https://www.c-plusplus.net/forum/218694-full

Keine passende Antwort gefunden?

Fragen Sie die Community