- #include <stdio.h>
- #include <winsock2.h>
- #pragma comment(lib, "ws2_32.lib")
-
-
-
- int main(int argc, char* argv[])
- {
-
-
-
- char *ip = "127.0.0.1";//ip de la machine a scnanner (dans ce cas-ci localhost)
- float o;
- o=0;
- float f;
- f=0;
- float x;
- float port;
- float port_max;
- float port_initial;
- port_initial = 20; //premier port a scanner
- port_max = 30; //dernier port a scanner
- x = port_max-port_initial;
-
-
- /* on initialise notre winsock */
- WSADATA WSAData;
- WSAStartup(MAKEWORD(2,0), &WSAData);
- /* fin d'initialisation */
-
-
- /* on construit notre socket */
- SOCKET sock;
- SOCKADDR_IN sin;
-
-
- for (port=port_initial ; port <= port_max ; port++)
-
- do
- {
- sock = socket(AF_INET, SOCK_STREAM, 0);
- sin.sin_addr.s_addr = inet_addr(ip);
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- if((connect(sock,(struct sockaddr*)&sin,sizeof(struct sockaddr))) == 0)
- {
- printf("Port %.f ouvert\n",port);
- o++;
- }
- else
- {
- printf("Port %.f Ferme\n",port);
- f++;
- }
- port++;
- }
- while(port < port_max);
-
-
- printf("\n\nAnalyse terminee avec succes !\n\n");
- printf("%.f ports ont ete scannes :)\n", x);
- printf("%.f port ouvert et %.f port ferme", o, f);
- printf("\n\n\nAppuyez sur une touche pour quitter");
-
- getchar();
-
- WSACleanup(); //on libére les ressources allouées
- closesocket(sock); //on ferme le socket
-
- return 0;
-
- }//fin int main
#include <stdio.h>
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
int main(int argc, char* argv[])
{
char *ip = "127.0.0.1";//ip de la machine a scnanner (dans ce cas-ci localhost)
float o;
o=0;
float f;
f=0;
float x;
float port;
float port_max;
float port_initial;
port_initial = 20; //premier port a scanner
port_max = 30; //dernier port a scanner
x = port_max-port_initial;
/* on initialise notre winsock */
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
/* fin d'initialisation */
/* on construit notre socket */
SOCKET sock;
SOCKADDR_IN sin;
for (port=port_initial ; port <= port_max ; port++)
do
{
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr(ip);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
if((connect(sock,(struct sockaddr*)&sin,sizeof(struct sockaddr))) == 0)
{
printf("Port %.f ouvert\n",port);
o++;
}
else
{
printf("Port %.f Ferme\n",port);
f++;
}
port++;
}
while(port < port_max);
printf("\n\nAnalyse terminee avec succes !\n\n");
printf("%.f ports ont ete scannes :)\n", x);
printf("%.f port ouvert et %.f port ferme", o, f);
printf("\n\n\nAppuyez sur une touche pour quitter");
getchar();
WSACleanup(); //on libére les ressources allouées
closesocket(sock); //on ferme le socket
return 0;
}//fin int main