Scanner d'ip

Description

Ce programe scane une plage d'ip et cherche dans celle ci quel son celle qui otorise une connection par le port 21 (FTP) en temps qu'anonymous.

Source / Exemple :


#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Wininet.h>

HINTERNET internet_ok;
HANDLE thboot;
int tmp,tmp2,tmp3,tmp4,tmp5,nb;
char ftp_ip[16];
char ftp_ip2[16];
char ftp_ip3[16]; 
char ftp_ip4[16]; 
char ftp_ip5[16]; 
   
conint()
{
    internet_ok = InternetOpen("", 1, "", "", 0);
	if ( internet_ok == NULL )
	{ 
        printf("Impossible de se connecter a internet.\n");
        return(1);
    } else
    {
        printf("Connection a internet Reussi.\n");
        return(0);
    }    
}     

DWORD WINAPI conftp(LPVOID ftp_ipnb_tmp)
{
    char * ftp_ipnb = (char*) ftp_ipnb_tmp;
    HINTERNET ftp_ok;
    char ftp_ip_bis[16];
    
    if (!strcmp(ftp_ipnb,"1"))
    {
        strcpy(ftp_ip_bis,ftp_ip);
        tmp=0;
    }else if (!strcmp(ftp_ipnb,"2"))
    {
        strcpy(ftp_ip_bis,ftp_ip2);
        tmp2=0;
    }else if (!strcmp(ftp_ipnb,"3"))
    {
        strcpy(ftp_ip_bis,ftp_ip3);
        tmp3=0;
    }else if (!strcmp(ftp_ipnb,"4"))
    {
        strcpy(ftp_ip_bis,ftp_ip4);
        tmp4=0;
    }else if (!strcmp(ftp_ipnb,"5"))
    {
        strcpy(ftp_ip_bis,ftp_ip5);
        tmp5=0;
    }else
    {
        nb--;
        printf("ERREUR");
        system("pause");
        return(0);
    }
    
    ftp_ok = InternetConnect ( internet_ok, ftp_ip_bis, 21, "anonymous", "aze@aze.com", INTERNET_SERVICE_FTP, 0, 0);  
    if ( ftp_ok == NULL )
    { 
        //DWORD errorCode = GetLastError();
        //printf("Impossible de se connecter au FTP(%d).\n",errorCode);
        //printf("Impossible : %d\n",errorCode);
        nb--;
        return(1);
    } else
    {
        printf("\t\t\t\t%s\n",ftp_ip_bis);
        nb--;
        InternetCloseHandle(ftp_ok);
        return(0); 
    }         
}    

main()
{
    DWORD deb, fin;
    int d1,d2,d3,d4,f1,f2,f3,f4,tmp_tmp;
    
    if (conint() == 1)       //connection a internet
        return(1);
    
    printf("Scan de l'ip : ");
    scanf("%d.%d.%d.%d",&d1,&d2,&d3,&d4);
    printf("A l'ip : ");
    scanf("%d.%d.%d.%d",&f1,&f2,&f3,&f4);
    printf("\nScan de d'ip %d.%d.%d.%d a l'ip %d.%d.%d.%d :\n",d1,d2,d3,d4,f1,f2,f3,f4);
    deb = GetTickCount();       //   debut du crono  //
    if (d1!=f1)
    {
        for(;d1<=f1;d1++)
        {
            for(;d2<256;d2++)
            {
                for(;d3<256;d3++)
                {
                    for(;d4<256;d4++)
                    {
                        while(tmp_tmp == 0)
                        {
                            while (nb>800)
                            sleep(500);
                            if (tmp == 0)
                            {
                                tmp=tmp_tmp=1;
                                sprintf(ftp_ip,"%d.%d.%d.%d",d1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"1", 0, NULL)) == NULL);
                            }else if (tmp2 == 0)
                            {
                                tmp2=tmp_tmp=1;
                                sprintf(ftp_ip2,"%d.%d.%d.%d",d1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"2", 0, NULL)) == NULL);
                            }else if (tmp3 == 0)
                            {
                                tmp3=tmp_tmp=1;
                                sprintf(ftp_ip3,"%d.%d.%d.%d",d1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"3", 0, NULL)) == NULL);
                            }else if (tmp4 == 0)
                            {
                                tmp4=tmp_tmp=1;
                                sprintf(ftp_ip4,"%d.%d.%d.%d",d1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"4", 0, NULL)) == NULL);
                            }else if (tmp5 == 0)
                            {
                                tmp5=tmp_tmp=1;
                                sprintf(ftp_ip5,"%d.%d.%d.%d",d1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"5", 0, NULL)) == NULL);
                            } else
                            sleep(1);
                        }
                        tmp_tmp = 0;
                        
                    }
                    d4=0;
                }
                d3=0;
            }
            d2=0;
        } 
    }    
        
    if (d2!=f2)
    {
        for(;d2<=f2;d2++)
        {
            for(;d3<256;d3++)
            {
                for(;d4<256;d4++)
                {
                        while(tmp_tmp == 0)
                        {
                            while (nb>800)
                            sleep(500);
                            if (tmp == 0)
                            {
                                tmp=tmp_tmp=1;
                                sprintf(ftp_ip,"%d.%d.%d.%d",f1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"1", 0, NULL)) == NULL);
                            }else if (tmp2 == 0)
                            {
                                tmp2=tmp_tmp=1;
                                sprintf(ftp_ip2,"%d.%d.%d.%d",f1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"2", 0, NULL)) == NULL);
                            }else if (tmp3 == 0)
                            {
                                tmp3=tmp_tmp=1;
                                sprintf(ftp_ip3,"%d.%d.%d.%d",f1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"3", 0, NULL)) == NULL);
                            }else if (tmp4 == 0)
                            {
                                tmp4=tmp_tmp=1;
                                sprintf(ftp_ip4,"%d.%d.%d.%d",f1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"4", 0, NULL)) == NULL);
                            }else if (tmp5 == 0)
                            {
                                tmp5=tmp_tmp=1;
                                sprintf(ftp_ip5,"%d.%d.%d.%d",f1,d2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"5", 0, NULL)) == NULL);
                            } else
                            sleep(1);    
                        }
                        tmp_tmp = 0;
                }
                d4=0;
            }
            d3=0;
        }
    }     
        
    if (d3!=f3)
    {
        for(;d3<=f3;d3++)
        {
            for(;d4<256;d4++)
            {
                        while(tmp_tmp == 0)
                        {
                            while (nb>800)
                            sleep(500);
                            if (tmp == 0)
                            {
                                tmp=tmp_tmp=1;
                                sprintf(ftp_ip,"%d.%d.%d.%d",f1,f2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"1", 0, NULL)) == NULL);
                            }else if (tmp2 == 0)
                            {
                                tmp2=tmp_tmp=1;
                                sprintf(ftp_ip2,"%d.%d.%d.%d",f1,f2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"2", 0, NULL)) == NULL);
                            }else if (tmp3 == 0)
                            {
                                tmp3=tmp_tmp=1;
                                sprintf(ftp_ip3,"%d.%d.%d.%d",f1,f2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"3", 0, NULL)) == NULL);
                            }else if (tmp4 == 0)
                            {
                                tmp4=tmp_tmp=1;
                                sprintf(ftp_ip4,"%d.%d.%d.%d",f1,f2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"4", 0, NULL)) == NULL);
                            }else if (tmp5 == 0)
                            {
                                tmp5=tmp_tmp=1;
                                sprintf(ftp_ip5,"%d.%d.%d.%d",f1,f2,d3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"5", 0, NULL)) == NULL);
                            } else
                            sleep(1);    
                        }
                        tmp_tmp = 0;
            }
            d4=0;
        }
    }        

    if (d4!=f4)
    {
        for(;d4<=f4;d4++)
        {
                        while(tmp_tmp == 0)
                        {
                            while (nb>800)
                            sleep(500);
                            if (tmp == 0)
                            {
                                tmp=tmp_tmp=1;
                                sprintf(ftp_ip,"%d.%d.%d.%d",f1,f2,f3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"1", 0, NULL)) == NULL);
                            }else if (tmp2 == 0)
                            {
                                tmp2=tmp_tmp=1;
                                sprintf(ftp_ip2,"%d.%d.%d.%d",f1,f2,f3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"2", 0, NULL)) == NULL);
                            }else if (tmp3 == 0)
                            {
                                tmp3=tmp_tmp=1;
                                sprintf(ftp_ip3,"%d.%d.%d.%d",f1,f2,f3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"3", 0, NULL)) == NULL);
                            }else if (tmp4 == 0)
                            {
                                tmp4=tmp_tmp=1;
                                sprintf(ftp_ip4,"%d.%d.%d.%d",f1,f2,f3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"4", 0, NULL)) == NULL);
                            }else if (tmp5 == 0)
                            {
                                tmp5=tmp_tmp=1;
                                sprintf(ftp_ip5,"%d.%d.%d.%d",f1,f2,f3,d4);
                                nb++;
                                while((thboot = CreateThread(NULL, 0, conftp , &"5", 0, NULL)) == NULL);
                            } else
                            sleep(1);    
                        }
                        tmp_tmp = 0;
        }
    }     
    fin = GetTickCount();       //   debut du crono  //
    printf("Tout les thread lancer en %d Ms\n",fin-deb);   
    while(nb!=0)
    sleep(500);
    fin = GetTickCount();       //   debut du crono  //
    printf("Scan fini en %d Ms\n",fin-deb);
    system("PAUSE");
}

Conclusion :


Si vous avez des idéés pour acceleré le programe, n'esiter pas a le dir pour que je puisse l'updater.
Elle scanne actuellement 2805 IP en 87Sec.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.