[这个贴子最后由黑色海岸线在 2004/10/09 03:25pm 第 2 次编辑]
/* this program should be compiled with gcc in linux
it belongs to www.thysea.com and be programmed by
blackghost.
copyright@www.thysea.com
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
///////////////////////
struct SPORT{
int min;
int max;
};
struct ADDR{
char min[15];
char max[15];
} addr_in;
struct DADDR{
int addr[4];
}min,max;
static int ipcount=0;
int connecttcp(long addr,int port);
int cmpip(int * min,int *max);
int getnextip();
int exdtoc(int*a);
//////////////////////
int main(int argc,char *argv[])
{
struct SPORT sport;
int nsock;
long count=0;
int cport=0;
int l=0;
for(;l<4;l++)
min.addr[l]=max.addr[l]=0;
printf("input the port limit\n");
scanf("%d,%d",&sport.min,&sport.max);
printf("input the low ip and high ip:\n");
scanf("%d.%d.%d.%d",&min.addr[0],&min.addr[1],&min.addr[2],&min.addr[3]);
scanf("%d.%d.%d.%d",&max.addr[0],&max.addr[1],&max.addr[2],&max.addr[3]);
//assume min0)
{
printf("error min>max\n");
exit(0);
}
while(getnextip()==0)
{
printf("this is the scan of ip=%s\n",addr_in.min);
for(cport=sport.min;cport0)
{
printf("yeah %d is ok!\n",cport);
shutdown(nsock,2);
}
}
}
printf("scan is over,bye");
exit(0);
}
int connecttcp(long addr,int port){
struct sockaddr_in sin;
int s;
memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;
sin.sin_port=htons(port);
sin.sin_addr.s_addr=addr;
s=socket(PF_INET,SOCK_STREAM,0);
if(s<0)
{ printf("error create socket\n");
return -1;
}
if(connect(s,(struct sockaddr*)&sin,sizeof(sin))<0)
{
printf("can't connect to %d\n",port);
return -2;
}
return s;
}
int cmpip(int *min,int *max){
if(min[0]>max[0])
return 1;
else
{
if(min[0]max[1])
return 1;
else
{
if(min[1]max[2])
return 1;
else
{
if(min[2]max[3])
return 1;
else
return 0;
}
}
}
}
}
}
}
int getnextip(){
if(min.addr[3]==255)
{
min.addr[3]=0;
if(min.addr[2]==255)
{
min.addr[2]=0;
if(min.addr[1]==255)
{
min.addr[1]=0;
if(min.addr[0]==255)
{printf("error too large ip,i can't think it is possible?
\n");
exit(0);
}
else
min.addr[0]++;
}
else
min.addr[1]++;
}
else
min.addr[2]++;
}
else
min.addr[3]++;
if(cmpip(min.addr,max.addr)>0)
{
printf("scan over,thank you for use \n");
exit(0);
}
return exdtoc(min.addr);
}
int exdtoc(int* a){
int itmp,dtmp;
int i=0,j=0,k=0;
char cstack[3];
for(;i<4;i++)
{
itmp=a;k=0;
while(itmp/10!=0){
cstack[k++]=(char)(itmp%10+48);
itmp/=10;
}
cstack[k]=(char)(itmp+48);
for(;k>=0;k--)
addr_in.min[j++]=cstack[k];
if(i<3)
addr_in.min[j++]='.';
}
addr_in.min[j]=0;
return 0;
}
-- 我就是blackghost
|