Всем привет. К теме форума относится косвенно, но как пример работы с сетью самое то. Мб вы пишете сетевого червя? Тогда для сетевого червя нужно заменить инкремент портов на рандом айпи =D
Код:
#include <iostream>
#include <cstdlib>
#include <winsock2.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib");
using namespace std;
int error,p_start,p_end;
char ip[] = "111.111.111.111";
HANDLE hThread;
DWORD dwThreadId;
int iSize;
int j;
int n = 0;
DWORD WINAPI scan(LPVOID param)
{
n++;
WSADATA wsa;
int prt = j;
SOCKET s;
SOCKADDR_IN a;
WSAStartup(0x0101,&wsa);
a.sin_family = AF_INET;
a.sin_addr.s_addr = inet_addr(ip);
s = socket(AF_INET,SOCK_STREAM,0);
a.sin_port = htons(prt);
int err = (connect(s,(sockaddr*)&a,sizeof(a)));
if (err==0)
{
cout << prt << " - Opened";
if (prt == 21) cout << " (ftp) " << endl;
if (prt == 80) cout << " (http) " << endl;
if (prt == 23) cout << " (telnet) " << endl;
if (prt == 25) cout << " (smtp) " << endl;
if (prt == 3389) cout << " (rdp) " << endl;
if (prt == 22) cout << " (ssh) " << endl;
if (prt == 5631) cout << " (PC Anywhere) " << endl;
if (prt == 110) cout << " (pop3) " << endl;
if (prt == 143) cout << " (imap) " << endl;
if (prt == 443) cout << " (http) " << endl;
if (prt == 135) cout << " (DCOM) " << endl;
if (prt == 445) cout << " (smb) " << endl;
if (prt == 1604) cout << " (probably DarkComet RAT) " << endl;
if (prt == 5222) cout << " (xmpp) " << endl;
cout << endl;
}
if (n == (p_end-p_start)) cout << "Scan finished!" << endl;
shutdown(s,2);
closesocket(s);
WSACleanup();
ExitThread(0);
}
int main()
{
cout << "From> ";
cin >> p_start;
cout << "To > ";
cin >> p_end;
cout << "IP: ";
cin >> ip;
for (j = p_start; j <= p_end; j++)
{
hThread = CreateThread(NULL, 0, scan,
(LPVOID)scan, 0, &dwThreadId);
Sleep(5);
}
system("pause >nul");
printf("thank you for using this scanner\n");
Sleep(500);
ExitProcess(0);
}
Компиль Dev-C++