begin process at 2012 02 09 19:06:38
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseaux & Internet

 > PORTS SCAN' VC++

PORTS SCAN' VC++


 Information sur la source

Note :
8,33 / 10 - par 3 personnes
8,33 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Réseaux & Internet Niveau :Initié Date de création :17/02/2002 Date de mise à jour :17/02/2002 18:41:24 Vu / téléchargé :7 009 / 424

Auteur : Lion7

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Ce scanner de port, avec interface win32, est tout simple, il scanne les ports sur un remote_host donné via l'header winsock.
A venir: -scan multi IPs / multi ports
             -scan réseau
             -fonctions avancés

Source

  • // scanner1.cpp : Defines the entry point for the application.
  • //
  • #include "stdafx.h"
  • #include "stdio.h"
  • #include "resource.h"
  • #include "winsock.h"
  • #include <cstdlib>
  • #include "limits.h"
  • struct hostent *hs;
  • SOCKET sock;
  • SOCKADDR_IN addr;
  • WSADATA wsa;
  • WORD wVersionRequested;
  • const char foo[] = "Port %d ouvert.";
  • const char foo2[] = "Port %d fermé.";
  • const char foo3[] = "Host %d inconnu.";
  • const char foo4[] = "Connection sur port %d à échoué.";
  • char *buf;
  • char *foobar(int port)
  • {
  • buf = new char [sizeof(foo) + INT_MAX%10];
  • sprintf(buf, foo, port);
  • return buf;
  • }
  • char *foobar2(int port)
  • {
  • buf = new char [sizeof(foo2) + INT_MAX%10];
  • sprintf(buf, foo2, port);
  • return buf;
  • }
  • char *foobar3(char *host)
  • {
  • buf = new char [sizeof(foo3) + INT_MAX%10];
  • sprintf(buf, foo3, host);
  • return buf;
  • }
  • char *foobar4(int port)
  • {
  • buf = new char [sizeof(foo4) + INT_MAX%10];
  • sprintf(buf, foo4, port);
  • return buf;
  • }
  • BOOL CALLBACK DIALOGProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
  • {
  • int i;
  • int openport=0;
  • char rhost[30], final[30], b[30], c[30], r[30];
  • char *pf, *pf2, *pf3, *shost;
  • switch (uMsg)
  • {
  • case WM_INITDIALOG:
  • case WM_COMMAND:
  • switch (LOWORD(wParam))
  • {
  • case IDCANCEL:
  • EndDialog(hwndDlg,1);
  • break;
  • case IDSTOP:
  • closesocket(sock);
  • break;
  • case IDOK:
  • GetDlgItemText(hwndDlg,IDC_EDIT1, rhost, 65535);
  • GetDlgItemText(hwndDlg, IDC_EDIT2, b, 65535);
  • GetDlgItemText(hwndDlg, IDC_EDIT3, c, 65535);
  • int a = atoi(b);
  • int a2 = atoi(c);
  • wVersionRequested = MAKEWORD( 2, 0 );
  • if (WSAStartup(wVersionRequested , &wsa)!=0)
  • {
  • SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) "Init. Winsock a échoué." );
  • return -1;
  • }
  • if ((addr.sin_addr.s_addr=inet_addr(rhost))==-1)
  • {
  • if ((hs=gethostbyname(rhost))==NULL)
  • {
  • GetDlgItemText(hwndDlg, IDC_EDIT1, shost, 30);
  • pf2 = foobar3(shost);
  • SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf2 );
  • delete pf2;
  • return -1;
  • }
  • addr.sin_family = hs->h_addrtype;
  • memcpy((void *)&addr.sin_addr.s_addr,hs->h_addr,hs->h_length);
  • }
  • for (i=a2; i < a; i++)
  • {
  • if ((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)
  • {
  • SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) "Creation du socket impossible." );
  • return -1;
  • }
  • addr.sin_family = AF_INET;
  • addr.sin_port = htons(i);
  • if (connect(sock,(LPSOCKADDR)&addr,sizeof(addr))==SOCKET_ERROR)
  • {
  • pf = foobar2(i);
  • SendMessage(GetDlgItem(hwndDlg, IDC_LIST2),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf );
  • delete pf;
  • pf3 = foobar4(i);
  • SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf3 );
  • delete pf3;
  • }
  • else{
  • itoa(i,r,10);
  • pf = foobar(i);
  • SendMessage(GetDlgItem(hwndDlg, IDC_LIST1),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf );
  • delete buf;
  • openport++;
  • }
  • closesocket(sock);
  • }
  • itoa(openport, final,10);
  • SetDlgItemText(hwndDlg, IDC_EDIT6, final);
  • break;
  • }
  • }
  • return false;
  • }
  • int WINAPI WinMain(HINSTANCE hInstance,
  • HINSTANCE hPrevInstance,
  • LPSTR lpCmdLine,
  • int nCmdShow)
  • {
  • int dlg;
  • dlg = DialogBox(hInstance,(LPCTSTR)IDD_DIALOG1,NULL,(DLGPROC) DIALOGProc);
  • return 0;
  • }
// scanner1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "stdio.h"
#include "resource.h"
#include "winsock.h"
#include <cstdlib>
#include "limits.h"

	  struct hostent       *hs;
      SOCKET               sock;
      SOCKADDR_IN          addr;
	  WSADATA              wsa;
   	  WORD                 wVersionRequested;

     const char foo[] = "Port %d ouvert."; 
	 const char foo2[] = "Port %d fermé.";
	 const char foo3[] = "Host %d inconnu.";
	 const char foo4[] = "Connection sur port %d à échoué.";
	 char *buf; 
      
	 	 char *foobar(int port) 
	   { 
       buf = new char [sizeof(foo) + INT_MAX%10]; 
       sprintf(buf, foo, port); 
       return buf; 
	  }

	    char *foobar2(int port) 
	   { 
       buf = new char [sizeof(foo2) + INT_MAX%10]; 
       sprintf(buf, foo2, port); 
       return buf; 
	  }

	 	 char *foobar3(char *host) 
	   { 
       buf = new char [sizeof(foo3) + INT_MAX%10]; 
       sprintf(buf, foo3, host); 
       return buf; 
	  }
	
		 char *foobar4(int port) 
	   { 
       buf = new char [sizeof(foo4) + INT_MAX%10]; 
       sprintf(buf, foo4, port); 
       return buf; 
	  }

	  BOOL CALLBACK DIALOGProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
	{ 
	int i;
	int openport=0;
	char rhost[30], final[30], b[30], c[30], r[30];
	char *pf, *pf2, *pf3, *shost;
	    switch (uMsg)						
		 {
		case WM_INITDIALOG:
		 case WM_COMMAND:
			 switch (LOWORD(wParam))
			 {
			 case IDCANCEL:
				 EndDialog(hwndDlg,1);
				 break;
			 case IDSTOP:
				 closesocket(sock);
				 break;
			 case IDOK:
				 GetDlgItemText(hwndDlg,IDC_EDIT1, rhost, 65535);
				 GetDlgItemText(hwndDlg, IDC_EDIT2, b, 65535);
                 GetDlgItemText(hwndDlg, IDC_EDIT3, c, 65535);
				 int a = atoi(b);
				 int a2 = atoi(c);

		  wVersionRequested = MAKEWORD( 2, 0 );
          if (WSAStartup(wVersionRequested , &wsa)!=0)
	{
		SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) "Init. Winsock a échoué." );
		return -1;    
	}
	if ((addr.sin_addr.s_addr=inet_addr(rhost))==-1)
	{
		if ((hs=gethostbyname(rhost))==NULL)
		{
		GetDlgItemText(hwndDlg, IDC_EDIT1, shost, 30);
        pf2 = foobar3(shost);
		SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf2 );
		delete pf2;
			return -1;
		}
		addr.sin_family = hs->h_addrtype;
		memcpy((void *)&addr.sin_addr.s_addr,hs->h_addr,hs->h_length);
	}

	for (i=a2; i < a; i++)
	{

	if ((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)
	{
	 SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) "Creation du socket impossible." );
		return -1;
	}

	addr.sin_family     = AF_INET;
	addr.sin_port       = htons(i);

	if (connect(sock,(LPSOCKADDR)&addr,sizeof(addr))==SOCKET_ERROR)
    {
	   pf = foobar2(i);
	   SendMessage(GetDlgItem(hwndDlg, IDC_LIST2),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf );
	   delete pf;
	   pf3 = foobar4(i);
       SendMessage(GetDlgItem(hwndDlg, IDC_LIST3),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf3 );
	   delete pf3;
    }
	else{
		itoa(i,r,10);
		pf = foobar(i);
	    SendMessage(GetDlgItem(hwndDlg, IDC_LIST1),LB_INSERTSTRING,-1,(LPARAM)(LPCTSTR) pf );
		delete buf;
		openport++;
	  }
	closesocket(sock);
	}
		 itoa(openport, final,10);
				 SetDlgItemText(hwndDlg, IDC_EDIT6, final);
				 break;
			 }
		 }

		 return false;

	}

	
int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	int dlg;
    dlg = DialogBox(hInstance,(LPCTSTR)IDD_DIALOG1,NULL,(DLGPROC) DIALOGProc);
	return 0;
} 


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

QUI VEUX JOUER ?
LIONSMATHS FINAL (DEV-C++)
DES MATHS... ENCORE! (DEV-C++)
MATHS... (DEV-C++)

 Sources de la même categorie

Source avec Zip SERVEUR MULTITHREAD [LINUX/WIN] par nipepsinicolas
Source avec Zip Source avec une capture SECURE REMOTE SHELL [WIN32] par ganjarasta
Source avec Zip Source avec une capture SUIVI DE PRODUCTION ONDULEUR PHOTOVOLTAÏQUE SOLARMAX par brunovan
Source avec Zip MINICHAT MULTI-CLIENT par wisar
SOCKET CPP par baptchr55

Commentaires et avis

Commentaire de Jctickle le 28/07/2008 01:40:25

Bonjour

Je voulais tout simplement savoir si il y a moyen de se procurer les fichiers .h svp, car pour la compilation, sa serai mieux.

Bien à vous.

Au revoir!

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,872 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales